jumpy scroll 2
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import SwiftUI
|
||||
|
||||
enum MDSegment {
|
||||
@@ -449,8 +450,10 @@ private struct FlowText: NSViewRepresentable {
|
||||
func size(_ text: NSAttributedString, _ width: CGFloat?) -> CGSize {
|
||||
let same = measured.map { $0.text === text || $0.text.isEqual(to: text) } ?? false
|
||||
if same, let m = measured, m.width == width {
|
||||
scrollLog.notice("measure hit len=\(text.length) width=\(width ?? -1) height=\(m.size.height)")
|
||||
return m.size
|
||||
}
|
||||
let start = ContinuousClock.now
|
||||
if !same {
|
||||
storage.setAttributedString(text)
|
||||
}
|
||||
@@ -458,6 +461,7 @@ private struct FlowText: NSViewRepresentable {
|
||||
layout.ensureLayout(for: container)
|
||||
let used = layout.usedRect(for: container)
|
||||
let size = CGSize(width: width ?? ceil(used.width), height: ceil(used.height))
|
||||
scrollLog.notice("measure miss len=\(text.length) width=\(width ?? -1) oldWidth=\(self.measured?.width ?? -1) newText=\(!same) height=\(size.height) ms=\((ContinuousClock.now - start) / .milliseconds(1))")
|
||||
measured = (text, width, size)
|
||||
return size
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user