Open files with the caret at the start !78

merged merged by cmc on 2026-10-06 03:19 UTC · krz/orgstar:caret-at-start into main

2 files changed, +7 −0

Layout: unified · split

Sources/OrgEditorAppKit/OrgEditor.swift +2
@@ -143,6 +143,8 @@ public final class OrgEditor: NSObject {
143143
144144 if isOrg { shaded.set(Presentation.shadedBlocks(document.tree)) }
145145 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))
146148 if isOrg {
147149 var startup = Presentation.startupFoldState(document.tree) ?? FoldState()
148150 let wrappers = Presentation.startupWrappers(document.tree, hideDrawers: options.hideDrawerStartup, hideBlocks: options.hideBlockStartup)
Tests/OrgEditorAppKitTests/EditorTests.swift +5
@@ -147,6 +147,11 @@ struct FoldingTests {
147147 #expect(pasteboard.string(forType: .string) == "* a\nbody\n** b\nmore\n* c\n")
148148 }
149149
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
150155 @Test func drawersFoldAtOpenAndToggleWithTab() {
151156 let text = "* a\n:PROPERTIES:\n:ID: x\n:END:\nbody\n#+begin_src sh\necho\n#+end_src\n* c\n"
152157 let h = Harness(text)