Skip to content

Commit 7ec98ff

Browse files
committed
feat: notes remember scroll position when navigating away and back, resets on app restart
1 parent a5fa087 commit 7ec98ff

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎EdgeMark/Core/Editor/MarkdownEditorView.swift‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ struct MarkdownEditorView: View {
5050
@State private var saveDebouncer = Debouncer(delay: 1.0)
5151
@State private var slashHandler = SlashCommandHandler()
5252
@State private var noteNavMonitor: Any?
53+
54+
/// Per-note scroll offsets persisted across editor unmount/remount (engine 0.12.0
55+
/// `onPersistScrollOffset` / `restoreScrollOffset`). Session-level — not persisted
56+
/// to disk (matches the engine's original coordinator-level offsets). Keyed by noteID.
57+
private static var scrollOffsets: [String: CGFloat] = [:]
5358
/// Latched at init — never updated on re-render. Guards against @Observable pushing
5459
/// a new selectedNote into the animating-out EditorScreen, which would overwrite
5560
/// onContentChanged's captured note ID while @State text still holds the old note's content.
@@ -130,6 +135,12 @@ struct MarkdownEditorView: View {
130135
AppSettings.shared.grammarCheckingEnabled = policy.grammarChecking
131136
AppSettings.shared.automaticSpellingCorrectionEnabled = policy.automaticSpellingCorrection
132137
},
138+
onPersistScrollOffset: { docId, offset in
139+
Self.scrollOffsets[docId] = offset
140+
},
141+
restoreScrollOffset: { docId in
142+
Self.scrollOffsets[docId]
143+
},
133144
)
134145
// Force the text view to rebuild (makeNSView) when the task-checkbox style
135146
// changes — the engine's updateNSView doesn't sync taskCheckbox, so only a

0 commit comments

Comments
 (0)