fix(editor): typography knob changes reach open surfaces (#71 follow-up 9)
updateNSView never fires on UserDefaults writes from the Settings pane, so the flowKey check there was dead code. Both surfaces now observe UserDefaults.didChangeNotification directly: the editor re-attributes (selection preserved), the reading canvas rebuilds its document. Also closes the parked stale-reading-view defect from the handoff notes.
This commit is contained in:
1 parent
677dc8c073
commit
0d3d5af78a
2 files changed
+53
-9
No files matched your search
@@ -79,6 +79,7 @@ struct ReadingSurface: NSViewRepresentable {
|
||||
tv.onEditIntent = onEditIntent
|
||||
tv.stateBox = stateBox
|
||||
context.coordinator.canvas = tv
|
||||
context.coordinator.watchDefaults(tv, representable: self)
|
||||
return scroll
|
||||
}
|
||||
|
||||
@@ -110,6 +111,29 @@ struct ReadingSurface: NSViewRepresentable {
|
||||
weak var canvas: ReadingCanvasView?
|
||||
var builtGeneration = -1
|
||||
var builtText = ""
|
||||
private var defaultsObserver: NSObjectProtocol?
|
||||
private var appliedFlowKey = ""
|
||||
|
||||
/// Rebuild the rendered document when typography/flow knobs move
|
||||
/// (SwiftUI doesn't re-call updateNSView on UserDefaults writes).
|
||||
func watchDefaults(_: ReadingCanvasView, representable: ReadingSurface) {
|
||||
guard defaultsObserver == nil else { return }
|
||||
appliedFlowKey = ProseTypography.flowKey
|
||||
defaultsObserver = NotificationCenter.default.addObserver(
|
||||
forName: UserDefaults.didChangeNotification,
|
||||
object: nil,
|
||||
queue: .main,
|
||||
) { [weak self] _ in
|
||||
guard let self, let canvas else { return }
|
||||
let key = ProseTypography.flowKey
|
||||
guard key != appliedFlowKey else { return }
|
||||
appliedFlowKey = key
|
||||
let doc = ReadingPresenter.document(for: representable.text, resolvingImagesIn: representable.postFolder)
|
||||
canvas.textStorage?.setAttributedString(doc.content)
|
||||
canvas.blockBounds = doc.bounds
|
||||
canvas.needsDisplay = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user