@@ -29,7 +29,7 @@ struct EdgeMarkImageProvider: EmbeddedImageProvider {
2929// MARK: - MarkdownEditorView
3030
3131/// SwiftUI wrapper around NativeTextViewWrapper (swift-markdown-engine).
32- /// Manages heading stripping , save debouncing, font observation, and the
32+ /// Manages full-document editing , save debouncing, font observation, and the
3333/// slash-command popup.
3434struct MarkdownEditorView : View {
3535 private struct EditorRebuildIdentity : Hashable {
@@ -55,7 +55,6 @@ struct MarkdownEditorView: View {
5555 var onNavigatePrevious : ( ( ) -> Void ) ?
5656
5757 @ State private var text : String
58- @ State private var hiddenHeadingLine : String
5958 @ State private var saveDebouncer = Debouncer ( delay : 1.0 )
6059 @ State private var slashHandler = SlashCommandHandler ( )
6160 @ State private var noteNavMonitor : Any ?
@@ -91,9 +90,7 @@ struct MarkdownEditorView: View {
9190 self . showFindBar = showFindBar
9291 self . onNavigateNext = onNavigateNext
9392 self . onNavigatePrevious = onNavigatePrevious
94- let ( heading , body ) = Self . splitHeading ( initialContent )
95- _text = State ( initialValue : Self . imagesToEmbeds ( body ) )
96- _hiddenHeadingLine = State ( initialValue : heading )
93+ _text = State ( initialValue : Self . imagesToEmbeds ( initialContent ) )
9794 _stableNoteID = State ( initialValue : noteID )
9895 }
9996
@@ -177,39 +174,20 @@ struct MarkdownEditorView: View {
177174 ) )
178175 . onChange ( of : text ) { _ , newText in
179176 slashHandler . contentDidSynchronize ( newText )
180- let heading = hiddenHeadingLine
181177 let noteIDSnapshot = stableNoteID
182178 saveDebouncer . call { [ onContentChanged ] in
183179 // Convert display-layer ![[path]] embeds back to on-disk  before saving.
184180 let storage = Self . embedsToImages ( newText )
185- let full = heading . isEmpty ? storage : heading + " \n \n " + storage
186- onContentChanged ( noteIDSnapshot , full )
181+ onContentChanged ( noteIDSnapshot , storage )
187182 }
188183 }
189184 . onChange ( of : pendingReload ) { _ , newContent in
190185 guard let newContent else { return }
191186 slashHandler . dismiss ( )
192187 saveDebouncer . cancel ( )
193- let ( heading , body ) = Self . splitHeading ( newContent )
194- hiddenHeadingLine = heading
195- text = Self . imagesToEmbeds ( body )
188+ text = Self . imagesToEmbeds ( newContent )
196189 pendingReload = nil
197190 }
198- . onChange ( of : noteTitle ) { _ , _ in
199- // A rename performed from the sticky title updates NoteStore's full
200- // content while this editor remains mounted. Keep the editor's hidden
201- // heading snapshot in sync so a pending debounce or onDisappear flush
202- // cannot write the previous title back into the note.
203- guard noteID == stableNoteID else { return }
204- slashHandler . dismiss ( )
205- saveDebouncer . cancel ( )
206- let ( heading , body ) = Self . splitHeading ( initialContent )
207- hiddenHeadingLine = heading
208- let displayBody = Self . imagesToEmbeds ( body )
209- if text != displayBody {
210- text = displayBody
211- }
212- }
213191 . overlay (
214192 ImageDropOverlay { [ noteID , noteTitle , noteFolder ] url in
215193 guard let data = try? Data ( contentsOf : url ) else { return }
@@ -278,8 +256,7 @@ struct MarkdownEditorView: View {
278256 let capturedID = stableNoteID
279257 saveDebouncer . cancel ( )
280258 let storage = Self . embedsToImages ( text )
281- let full = hiddenHeadingLine . isEmpty ? storage : hiddenHeadingLine + " \n \n " + storage
282- onContentChanged ( capturedID , full )
259+ onContentChanged ( capturedID , storage )
283260 slashHandler . dismiss ( )
284261 if let m = noteNavMonitor {
285262 NSEvent . removeMonitor ( m ) ; noteNavMonitor = nil
@@ -289,16 +266,6 @@ struct MarkdownEditorView: View {
289266
290267 // MARK: - Helpers
291268
292- static func splitHeading ( _ content : String ) -> ( heading : String , body : String ) {
293- let lines = content . components ( separatedBy : " \n " )
294- guard let first = lines . first , first . hasPrefix ( " # " ) else { return ( " " , content ) }
295- var rest = Array ( lines . dropFirst ( ) )
296- while rest . first == " " {
297- rest . removeFirst ( )
298- }
299- return ( first , rest . joined ( separator : " \n " ) )
300- }
301-
302269 private static func resolvedFontFamily ( from postscriptName : String ? ) -> String ? {
303270 guard let name = postscriptName , let font = NSFont ( name : name , size : 16 ) else { return nil }
304271 return font . familyName
0 commit comments