Commit 6521f7f7d6
6521f7f7d6319fe4983de384af53a08140ce4f28
parent: 2e692ba274
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-06 03:19 UTC
Open files with the caret at the start
Replacing the text storage left the caret at the end of the file.
Changed files (2)
Sources/OrgEditorAppKit/OrgEditor.swift
+2 · view
| @@ -143,6 +143,8 @@ public final class OrgEditor: NSObject { |
| 143 | |
143 | |
| 144 | if isOrg { shaded.set(Presentation.shadedBlocks(document.tree)) } |
144 | if isOrg { shaded.set(Presentation.shadedBlocks(document.tree)) } |
| 145 | load(document.text) |
145 | load(document.text) |
| |
146 | // Files open at their start, as in Emacs; replacing the storage leaves it at the end. |
| |
147 | textView.setSelectedRange(NSRange(location: 0, length: 0)) |
| 146 | if isOrg { |
148 | if isOrg { |
| 147 | var startup = Presentation.startupFoldState(document.tree) ?? FoldState() |
149 | var startup = Presentation.startupFoldState(document.tree) ?? FoldState() |
| 148 | let wrappers = Presentation.startupWrappers(document.tree, hideDrawers: options.hideDrawerStartup, hideBlocks: options.hideBlockStartup) |
150 | let wrappers = Presentation.startupWrappers(document.tree, hideDrawers: options.hideDrawerStartup, hideBlocks: options.hideBlockStartup) |
Tests/OrgEditorAppKitTests/EditorTests.swift
+5 · view
| @@ -147,6 +147,11 @@ struct FoldingTests { |
| 147 | #expect(pasteboard.string(forType: .string) == "* a\nbody\n** b\nmore\n* c\n") |
147 | #expect(pasteboard.string(forType: .string) == "* a\nbody\n** b\nmore\n* c\n") |
| 148 | } |
148 | } |
| 149 | |
149 | |
| |
150 | @Test func opensWithTheCaretAtTheStart() { |
| |
151 | let h = Harness("* a\nbody\n* b\n") |
| |
152 | #expect(h.textView.selectedRange() == NSRange(location: 0, length: 0)) |
| |
153 | } |
| |
154 | |
| 150 | @Test func drawersFoldAtOpenAndToggleWithTab() { |
155 | @Test func drawersFoldAtOpenAndToggleWithTab() { |
| 151 | let text = "* a\n:PROPERTIES:\n:ID: x\n:END:\nbody\n#+begin_src sh\necho\n#+end_src\n* c\n" |
156 | let text = "* a\n:PROPERTIES:\n:ID: x\n:END:\nbody\n#+begin_src sh\necho\n#+end_src\n* c\n" |
| 152 | let h = Harness(text) |
157 | let h = Harness(text) |