jumpy scroll 3

This commit is contained in:
Ian Gulliver
2026-10-17 11:34:53 -07:00
parent 31037e1c9f
commit edb59a3718
3 changed files with 26 additions and 23 deletions
-4
View File
@@ -1,4 +1,3 @@
import os
import SwiftUI
enum MDSegment {
@@ -536,10 +535,8 @@ 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)
}
@@ -547,7 +544,6 @@ 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
}