Commit 73230beed3
Verified · cmc
Layout: unified · split
Sources/OrgApp/PaneLayout.swift +6 −4
| @@ -46,15 +46,17 @@ public indirect enum PaneLayout: Equatable, Sendable { | |||
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | /// The split whose first pane in reading order is `id`, with `fraction` for its first side. | 49 | /// The split whose divider lies between `before` (the last pane of its first side) and |
| 50 | public func settingFraction(_ fraction: Double, ofSplitStartingWith id: PaneID) -> PaneLayout { | 50 | /// `after` (the first pane of its second side), with `fraction` for its first side. Each |
| 51 | /// split is one such adjacency in reading order, so the pair names it. | ||
| 52 | public func settingFraction(_ fraction: Double, ofSplitBetween before: PaneID, and after: PaneID) -> PaneLayout { | ||
| 51 | switch self { | 53 | switch self { |
| 52 | case .pane: self | 54 | case .pane: self |
| 53 | case .split(let axis, let first, let second, let old): | 55 | case .split(let axis, let first, let second, let old): |
| 54 | if first.panes.first == id { | 56 | if first.panes.last == before, second.panes.first == after { |
| 55 | .split(axis: axis, first: first, second: second, fraction: min(max(fraction, 0.1), 0.9)) | 57 | .split(axis: axis, first: first, second: second, fraction: min(max(fraction, 0.1), 0.9)) |
| 56 | } else { | 58 | } else { |
| 57 | .split(axis: axis, first: first.settingFraction(fraction, ofSplitStartingWith: id), second: second.settingFraction(fraction, ofSplitStartingWith: id), fraction: old) | 59 | .split(axis: axis, first: first.settingFraction(fraction, ofSplitBetween: before, and: after), second: second.settingFraction(fraction, ofSplitBetween: before, and: after), fraction: old) |
| 58 | } | 60 | } |
| 59 | } | 61 | } |
| 60 | } | 62 | } |
Sources/OrgEditorAppKit/OrgEditor+Folding.swift +13 −3
| @@ -29,10 +29,15 @@ extension OrgEditor { | |||
| 29 | view.wrapperFolds = Set(wrapperHidden.keys) | 29 | view.wrapperFolds = Set(wrapperHidden.keys) |
| 30 | updateHiddenAndLayout() | 30 | updateHiddenAndLayout() |
| 31 | redrawViews() | 31 | redrawViews() |
| 32 | caretsOutOfHiddenText() | ||
| 33 | } | ||
| 34 | |||
| 35 | /// Every view's caret moved to just before the hidden text it sits in, if any. | ||
| 36 | func caretsOutOfHiddenText() { | ||
| 32 | for view in textViews { | 37 | for view in textViews { |
| 33 | let caret = view.selectedRange().location | 38 | let caret = view.selectedRange().location |
| 34 | guard let range = hidden.containing(caret) else { continue } | 39 | guard let range = hidden.containing(caret) else { continue } |
| 35 | if view === active { setCaret(range.lowerBound - 1) } else { view.setSelectedRange(NSRange(location: max(0, range.lowerBound - 1), length: 0)) } | 40 | if view === active { setCaret(max(0, range.lowerBound - 1)) } else { view.setSelectedRange(NSRange(location: max(0, range.lowerBound - 1), length: 0)) } |
| 36 | } | 41 | } |
| 37 | } | 42 | } |
| 38 | 43 | ||
| @@ -131,8 +136,7 @@ extension OrgEditor { | |||
| 131 | restyleOutsideEditing(0..<utf16Length) | 136 | restyleOutsideEditing(0..<utf16Length) |
| 132 | } | 137 | } |
| 133 | redrawViews() | 138 | redrawViews() |
| 134 | let caret = textView.selectedRange().location | 139 | caretsOutOfHiddenText() |
| 135 | if let range = hidden.containing(caret) { setCaret(max(0, range.lowerBound - 1)) } | ||
| 136 | } | 140 | } |
| 137 | 141 | ||
| 138 | /// Leaves a sparse tree for ordinary folds: headings with something shown below them | 142 | /// Leaves a sparse tree for ordinary folds: headings with something shown below them |
| @@ -194,6 +198,12 @@ extension OrgEditor { | |||
| 194 | redrawViews() | 198 | redrawViews() |
| 195 | if let narrowed { | 199 | if let narrowed { |
| 196 | setCaret(max(narrowed.lowerBound, min(caret, narrowed.upperBound))) | 200 | setCaret(max(narrowed.lowerBound, min(caret, narrowed.upperBound))) |
| 201 | for view in textViews where view !== active { | ||
| 202 | let other = view.selectedRange().location | ||
| 203 | if !(narrowed.lowerBound...narrowed.upperBound).contains(other) { | ||
| 204 | view.setSelectedRange(NSRange(location: max(narrowed.lowerBound, min(other, narrowed.upperBound)), length: 0)) | ||
| 205 | } | ||
| 206 | } | ||
| 197 | textView.scrollRangeToVisible(NSRange(location: narrowed.lowerBound, length: 0)) | 207 | textView.scrollRangeToVisible(NSRange(location: narrowed.lowerBound, length: 0)) |
| 198 | } else { | 208 | } else { |
| 199 | textView.scrollRangeToVisible(NSRange(location: caret, length: 0)) | 209 | textView.scrollRangeToVisible(NSRange(location: caret, length: 0)) |
Sources/OrgEditorAppKit/OrgEditor.swift +5 −1
| @@ -137,8 +137,12 @@ public final class OrgEditor: NSObject { | |||
| 137 | view.onFocusChange = { [weak self, unowned view] in | 137 | view.onFocusChange = { [weak self, unowned view] in |
| 138 | guard let self, let layout = view.textLayoutManager else { return } | 138 | guard let self, let layout = view.textLayoutManager else { return } |
| 139 | let id = ObjectIdentifier(layout) | 139 | let id = ObjectIdentifier(layout) |
| 140 | if view.window?.firstResponder === view { | 140 | if view.window?.firstResponder === view, self.active !== view { |
| 141 | self.active = view | 141 | self.active = view |
| 142 | // Its caret may sit in text another view folded or narrowed away since. | ||
| 143 | self.selectionChanged() | ||
| 144 | self.onFocus?(view) | ||
| 145 | } else if view.window?.firstResponder === view { | ||
| 142 | self.onFocus?(view) | 146 | self.onFocus?(view) |
| 143 | } | 147 | } |
| 144 | if let window = view.window, window.isKeyWindow, window.firstResponder === view { | 148 | if let window = view.window, window.isKeyWindow, window.firstResponder === view { |
Sources/Orgstar/ContentView.swift +52 −9
| @@ -104,6 +104,21 @@ struct ContentView: View { | |||
| 104 | EditorSettings(keymap: keymap, modal: preset.isModal, optionAsMeta: OptionAsMeta(rawValue: optionAsMeta), options: options, showMarkup: showMarkup, showLineNumbers: showLineNumbers, theme: theme) | 104 | EditorSettings(keymap: keymap, modal: preset.isModal, optionAsMeta: OptionAsMeta(rawValue: optionAsMeta), options: options, showMarkup: showMarkup, showLineNumbers: showLineNumbers, theme: theme) |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | /// The pane that had the focus when a sheet opened, to act on when it closes. | ||
| 108 | @State private var sheetTarget: EditorPane? | ||
| 109 | |||
| 110 | /// Puts the focus back on the pane a sheet was opened from. | ||
| 111 | private func restoreSheetTarget() { | ||
| 112 | guard let target = sheetTarget, session.panes.contains(where: { $0 === target }) else { return } | ||
| 113 | sheetTarget = nil | ||
| 114 | session.focused = target | ||
| 115 | if let window = commands.store.window(of: target.id) { window.focused = target.id } | ||
| 116 | if let path = target.path, let textView = commands.store.textView(for: target.id, path: path) { | ||
| 117 | textView.window?.makeFirstResponder(textView) | ||
| 118 | commands.editor = commands.store.editor(for: path) | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 107 | /// The window holding the focused pane: this one, or an editor window. | 122 | /// The window holding the focused pane: this one, or an editor window. |
| 108 | private var paneWindow: WindowModel? { | 123 | private var paneWindow: WindowModel? { |
| 109 | commands.store.window(of: session.focused.id) ?? window | 124 | commands.store.window(of: session.focused.id) ?? window |
| @@ -270,11 +285,29 @@ struct ContentView: View { | |||
| 270 | .onAppear { | 285 | .onAppear { |
| 271 | commands.externalHandler = runExternal | 286 | commands.externalHandler = runExternal |
| 272 | commands.knownTags = { [index = workspace.index] in (try? index.tags()) ?? [] } | 287 | commands.knownTags = { [index = workspace.index] in (try? index.tags()) ?? [] } |
| 273 | if window == nil { | 288 | commands.mainWindowOpen = true |
| 274 | let model = WindowModel(session: session, pane: session.panes[0]) | 289 | if let stale = window { commands.store.windows.removeAll { $0 === stale } } |
| 275 | window = model | 290 | // The session's first pane the first time; a new one showing the focused buffer |
| 276 | commands.store.windows.append(model) | 291 | // when the window opens again. |
| 277 | } | 292 | let pane: EditorPane |
| 293 | if commands.store.window(of: session.panes[0].id) == nil, window == nil { | ||
| 294 | pane = session.panes[0] | ||
| 295 | } else { | ||
| 296 | pane = session.makePane() | ||
| 297 | if let path = session.focused.path { session.open(path, in: pane) } | ||
| 298 | } | ||
| 299 | let model = WindowModel(session: session, pane: pane) | ||
| 300 | window = model | ||
| 301 | commands.store.windows.insert(model, at: 0) | ||
| 302 | model.focus(pane.id) | ||
| 303 | } | ||
| 304 | .onDisappear { | ||
| 305 | commands.mainWindowOpen = false | ||
| 306 | guard let model = window else { return } | ||
| 307 | for id in model.layout.panes { commands.store.releasePane(id) } | ||
| 308 | model.closeAll() | ||
| 309 | commands.store.windows.removeAll { $0 === model } | ||
| 310 | commands.editor = nil | ||
| 278 | } | 311 | } |
| 279 | .onChange(of: saveMode, initial: true) { _, mode in session.saveMode = mode } | 312 | .onChange(of: saveMode, initial: true) { _, mode in session.saveMode = mode } |
| 280 | .onChange(of: options, initial: true) { _, options in session.options = options } | 313 | .onChange(of: options, initial: true) { _, options in session.options = options } |
| @@ -306,10 +339,16 @@ struct ContentView: View { | |||
| 306 | .sheet(isPresented: $commands.showingPalette) { | 339 | .sheet(isPresented: $commands.showingPalette) { |
| 307 | PaletteView(commands: commands) { id in | 340 | PaletteView(commands: commands) { id in |
| 308 | commands.showingPalette = false | 341 | commands.showingPalette = false |
| 309 | // After the sheet closes, so app commands can present their own. | 342 | // After the sheet closes, so app commands can present their own, and in the |
| 310 | DispatchQueue.main.async { perform(id) } | 343 | // pane that had the focus when it opened: closing a sheet makes this window key. |
| 344 | DispatchQueue.main.async { | ||
| 345 | restoreSheetTarget() | ||
| 346 | perform(id) | ||
| 347 | } | ||
| 311 | } | 348 | } |
| 312 | } | 349 | } |
| 350 | .onChange(of: commands.showingPalette) { _, showing in if showing { sheetTarget = session.focused } } | ||
| 351 | .onChange(of: commands.showingQuickOpen) { _, showing in if showing { sheetTarget = session.focused } } | ||
| 313 | .onChange(of: session.conflict) { _, conflict in | 352 | .onChange(of: session.conflict) { _, conflict in |
| 314 | if conflict != nil { commands.showingConflict = true } | 353 | if conflict != nil { commands.showingConflict = true } |
| 315 | } | 354 | } |
| @@ -333,7 +372,7 @@ struct ContentView: View { | |||
| 333 | hotKey?.unregister() | 372 | hotKey?.unregister() |
| 334 | hotKey = enabled ? GlobalHotKey { perform("app.capture") } : nil | 373 | hotKey = enabled ? GlobalHotKey { perform("app.capture") } : nil |
| 335 | } | 374 | } |
| 336 | .onChange(of: commands.runRequest?.serial) { | 375 | .onChange(of: commands.runRequest?.serial, initial: true) { |
| 337 | if let id = commands.runRequest?.id { perform(id) } | 376 | if let id = commands.runRequest?.id { perform(id) } |
| 338 | } | 377 | } |
| 339 | .onChange(of: ConfigSync.shared.problems, initial: true) { _, problems in | 378 | .onChange(of: ConfigSync.shared.problems, initial: true) { _, problems in |
| @@ -366,8 +405,12 @@ struct ContentView: View { | |||
| 366 | } | 405 | } |
| 367 | .sheet(isPresented: $commands.showingQuickOpen) { | 406 | .sheet(isPresented: $commands.showingQuickOpen) { |
| 368 | QuickOpenView(workspace: workspace) { entry in | 407 | QuickOpenView(workspace: workspace) { entry in |
| 369 | selectedFile = entry.path | ||
| 370 | commands.showingQuickOpen = false | 408 | commands.showingQuickOpen = false |
| 409 | DispatchQueue.main.async { | ||
| 410 | restoreSheetTarget() | ||
| 411 | selectedFile = entry.path | ||
| 412 | if selectedFile == entry.path { session.open(entry.path) } | ||
| 413 | } | ||
| 371 | } | 414 | } |
| 372 | } | 415 | } |
| 373 | .alert("orgstar", isPresented: errorShown) { | 416 | .alert("orgstar", isPresented: errorShown) { |
Sources/Orgstar/EditorWindowView.swift +10 −2
| @@ -9,16 +9,23 @@ struct EditorWindowView: View { | |||
| 9 | let clock: ClockModel | 9 | let clock: ClockModel |
| 10 | @AppStorage("showTabBar") private var showTabBar = false | 10 | @AppStorage("showTabBar") private var showTabBar = false |
| 11 | @State private var window: WindowModel? | 11 | @State private var window: WindowModel? |
| 12 | @Environment(\.openWindow) private var openWindow | ||
| 13 | |||
| 14 | /// App commands run in the main window; it comes back if it was closed. | ||
| 15 | private func run(_ id: String) { | ||
| 16 | if !commands.mainWindowOpen { openWindow(id: "main") } | ||
| 17 | commands.run(id) | ||
| 18 | } | ||
| 12 | 19 | ||
| 13 | var body: some View { | 20 | var body: some View { |
| 14 | Group { | 21 | Group { |
| 15 | if let window { | 22 | if let window { |
| 16 | PaneLayoutView(layout: window.layout, window: window) { pane in | 23 | PaneLayoutView(layout: window.layout, window: window) { pane in |
| 17 | PaneCell(pane: pane, window: window, session: session, commands: commands, showTabBar: showTabBar) { commands.run($0) } | 24 | PaneCell(pane: pane, window: window, session: session, commands: commands, showTabBar: showTabBar) { run($0) } |
| 18 | } | 25 | } |
| 19 | .safeAreaInset(edge: .bottom, spacing: 0) { | 26 | .safeAreaInset(edge: .bottom, spacing: 0) { |
| 20 | VStack(spacing: 0) { | 27 | VStack(spacing: 0) { |
| 21 | ModeLine(session: session, commands: commands, clock: clock) { commands.run($0) } | 28 | ModeLine(session: session, commands: commands, clock: clock) { run($0) } |
| 22 | EchoArea(commands: commands) | 29 | EchoArea(commands: commands) |
| 23 | } | 30 | } |
| 24 | } | 31 | } |
| @@ -39,6 +46,7 @@ struct EditorWindowView: View { | |||
| 39 | for id in model.layout.panes { commands.store.releasePane(id) } | 46 | for id in model.layout.panes { commands.store.releasePane(id) } |
| 40 | model.closeAll() | 47 | model.closeAll() |
| 41 | commands.store.windows.removeAll { $0 === model } | 48 | commands.store.windows.removeAll { $0 === model } |
| 49 | commands.editor = nil | ||
| 42 | if let main = commands.store.windows.first { main.focus(main.focused) } | 50 | if let main = commands.store.windows.first { main.focus(main.focused) } |
| 43 | } | 51 | } |
| 44 | } | 52 | } |
Sources/Orgstar/OrgstarApp.swift +4
| @@ -24,6 +24,9 @@ final class AppCommands { | |||
| 24 | var editor: OrgEditor? | 24 | var editor: OrgEditor? |
| 25 | /// The editors and text views of every pane in every window. | 25 | /// The editors and text views of every pane in every window. |
| 26 | let store = EditorStore() | 26 | let store = EditorStore() |
| 27 | /// The main window is on screen. App commands run there, so an editor window reopens it | ||
| 28 | /// before asking for one. | ||
| 29 | var mainWindowOpen = false | ||
| 27 | /// What every editor is set up with, from the settings; the main window keeps it current. | 30 | /// What every editor is set up with, from the settings; the main window keeps it current. |
| 28 | var editorSettings = EditorSettings() | 31 | var editorSettings = EditorSettings() |
| 29 | /// Runs work outside the text (a table recalculation in Emacs); the main window sets it. | 32 | /// Runs work outside the text (a table recalculation in Emacs); the main window sets it. |
| @@ -332,6 +335,7 @@ struct OrgstarApp: App { | |||
| 332 | } | 335 | } |
| 333 | } | 336 | } |
| 334 | .defaultSize(width: 900, height: 700) | 337 | .defaultSize(width: 900, height: 700) |
| 338 | .commandsRemoved() | ||
| 335 | Window("Agenda", id: "agenda") { | 339 | Window("Agenda", id: "agenda") { |
| 336 | if case .success(let model) = workspace { | 340 | if case .success(let model) = workspace { |
| 337 | AgendaView(workspace: model, session: session, commands: commands, scheduler: scheduler, clock: clock) | 341 | AgendaView(workspace: model, session: session, commands: commands, scheduler: scheduler, clock: clock) |
Sources/Orgstar/PaneLayoutView.swift +2 −1
| @@ -16,7 +16,7 @@ struct PaneLayoutView<Content: View>: View { | |||
| 16 | let total = axis == .horizontal ? geometry.size.width : geometry.size.height | 16 | let total = axis == .horizontal ? geometry.size.width : geometry.size.height |
| 17 | let firstSize = max(80, min(max(80, total - 80), total * fraction)) | 17 | let firstSize = max(80, min(max(80, total - 80), total * fraction)) |
| 18 | let divider = SplitDivider(axis: axis, firstSize: firstSize) { size in | 18 | let divider = SplitDivider(axis: axis, firstSize: firstSize) { size in |
| 19 | window.setFraction(size / max(total, 1), ofSplitStartingWith: first.panes[0]) | 19 | window.setFraction(size / max(total, 1), ofSplitBetween: first.panes[first.panes.count - 1], and: second.panes[0]) |
| 20 | } | 20 | } |
| 21 | if axis == .horizontal { | 21 | if axis == .horizontal { |
| 22 | HStack(spacing: 0) { | 22 | HStack(spacing: 0) { |
| @@ -81,6 +81,7 @@ struct PaneCell: View { | |||
| 81 | .contentShape(Rectangle()) | 81 | .contentShape(Rectangle()) |
| 82 | .onTapGesture { | 82 | .onTapGesture { |
| 83 | window.focus(pane.id) | 83 | window.focus(pane.id) |
| 84 | NSApp.keyWindow?.makeFirstResponder(nil) | ||
| 84 | commands.editor = nil | 85 | commands.editor = nil |
| 85 | } | 86 | } |
| 86 | } | 87 | } |
Sources/Orgstar/WindowModel.swift +5 −5
| @@ -21,7 +21,7 @@ final class WindowModel: Identifiable { | |||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | func pane(_ id: PaneID) -> EditorPane? { panes[id] } | 23 | func pane(_ id: PaneID) -> EditorPane? { panes[id] } |
| 24 | var focusedPane: EditorPane { panes[focused] ?? panes[layout.panes[0]]! } | 24 | var focusedPane: EditorPane { panes[focused] ?? panes[layout.panes[0]] ?? panes.values.first ?? session.focused } |
| 25 | var paneCount: Int { layout.panes.count } | 25 | var paneCount: Int { layout.panes.count } |
| 26 | 26 | ||
| 27 | /// A new pane after the focused one, showing the same buffer, as `split-window` does. The | 27 | /// A new pane after the focused one, showing the same buffer, as `split-window` does. The |
| @@ -61,13 +61,13 @@ final class WindowModel: Identifiable { | |||
| 61 | session.focused = pane | 61 | session.focused = pane |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | func setFraction(_ fraction: Double, ofSplitStartingWith id: PaneID) { | 64 | func setFraction(_ fraction: Double, ofSplitBetween before: PaneID, and after: PaneID) { |
| 65 | layout = layout.settingFraction(fraction, ofSplitStartingWith: id) | 65 | layout = layout.settingFraction(fraction, ofSplitBetween: before, and: after) |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | /// Takes every pane out of the session, as the window closes. | 68 | /// Takes every pane out of the session, as the window closes. The panes stay listed here |
| 69 | /// so views still on screen can read them. | ||
| 69 | func closeAll() { | 70 | func closeAll() { |
| 70 | for pane in panes.values { session.closePane(pane) } | 71 | for pane in panes.values { session.closePane(pane) } |
| 71 | panes = [:] | ||
| 72 | } | 72 | } |
| 73 | } | 73 | } |
Tests/OrgAppTests/PaneLayoutTests.swift +6 −2
| @@ -22,9 +22,13 @@ struct PaneLayoutTests { | |||
| 22 | @Test func settingAFractionFindsTheSplitByItsFirstPane() { | 22 | @Test func settingAFractionFindsTheSplitByItsFirstPane() { |
| 23 | let a = PaneID(), b = PaneID(), c = PaneID() | 23 | let a = PaneID(), b = PaneID(), c = PaneID() |
| 24 | let layout = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(b, axis: .vertical, new: c) | 24 | let layout = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(b, axis: .vertical, new: c) |
| 25 | let inner = layout.settingFraction(0.3, ofSplitStartingWith: b) | 25 | let inner = layout.settingFraction(0.3, ofSplitBetween: b, and: c) |
| 26 | #expect(inner == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.3), fraction: 0.5)) | 26 | #expect(inner == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.3), fraction: 0.5)) |
| 27 | #expect(layout.settingFraction(2, ofSplitStartingWith: a) == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.5), fraction: 0.9)) | 27 | #expect(layout.settingFraction(2, ofSplitBetween: a, and: b) == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.5), fraction: 0.9)) |
| 28 | // A nested split on the first side shares its first pane with the outer split. | ||
| 29 | let nestedFirst = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(a, axis: .vertical, new: c) | ||
| 30 | #expect(nestedFirst.settingFraction(0.3, ofSplitBetween: a, and: c) == .split(axis: .horizontal, first: .split(axis: .vertical, first: .pane(a), second: .pane(c), fraction: 0.3), second: .pane(b), fraction: 0.5)) | ||
| 31 | #expect(nestedFirst.settingFraction(0.3, ofSplitBetween: c, and: b) == .split(axis: .horizontal, first: .split(axis: .vertical, first: .pane(a), second: .pane(c), fraction: 0.5), second: .pane(b), fraction: 0.3)) | ||
| 28 | } | 32 | } |
| 29 | 33 | ||
| 30 | @Test func onlyAndNext() { | 34 | @Test func onlyAndNext() { |
Tests/OrgEditorAppKitTests/MultiViewTests.swift +18
| @@ -81,6 +81,24 @@ struct MultiViewTests { | |||
| 81 | #expect(two.second.string == "XY* a\nbody\n") | 81 | #expect(two.second.string == "XY* a\nbody\n") |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | @Test func narrowingMovesEveryViewsCaretIntoTheRegion() { | ||
| 85 | let two = Two("* a\nbody\n* b\nmore\n") | ||
| 86 | two.second.setSelectedRange(NSRange(location: 0, length: 0)) | ||
| 87 | two.editor.setCaret(9) | ||
| 88 | two.editor.run("org.narrow.subtree") | ||
| 89 | #expect(two.editor.narrowed?.lowerBound == 9) | ||
| 90 | #expect(two.second.selectedRange().location >= 9) | ||
| 91 | } | ||
| 92 | |||
| 93 | @Test func aViewTakingFocusLeavesHiddenText() { | ||
| 94 | let two = Two("* a\nbody\n* b\nmore\n") | ||
| 95 | two.second.setSelectedRange(NSRange(location: 5, length: 0)) | ||
| 96 | two.editor.setCaret(0) | ||
| 97 | _ = two.editor.cycleAtCaret() | ||
| 98 | two.windows[1].makeFirstResponder(two.second) | ||
| 99 | #expect(two.editor.hidden.containing(two.second.selectedRange().location) == nil) | ||
| 100 | } | ||
| 101 | |||
| 84 | @Test func removingAViewDetachesItsLayoutManager() { | 102 | @Test func removingAViewDetachesItsLayoutManager() { |
| 85 | let two = Two("* a\n") | 103 | let two = Two("* a\n") |
| 86 | let storage = two.editor.textView.textLayoutManager!.textContentManager! | 104 | let storage = two.editor.textView.textLayoutManager!.textContentManager! |
docs/plans/2026-10-10-windows-and-panes.md +6
| @@ -155,3 +155,9 @@ public indirect enum PaneLayout: Equatable, Sendable { | |||
| 155 | - `WindowModel` (app) holds a window's `PaneLayout`, its panes and the focused one; `AppCommands.store.windows` lists them so pane commands find the window of the focused pane. | 155 | - `WindowModel` (app) holds a window's `PaneLayout`, its panes and the focused one; `AppCommands.store.windows` lists them so pane commands find the window of the focused pane. |
| 156 | - A split shows the same buffer in the new pane and keeps the focus, as `split-window` does. A pane with no buffer shows a placeholder. | 156 | - A split shows the same buffer in the new pane and keeps the focus, as `split-window` does. A pane with no buffer shows a placeholder. |
| 157 | - Checked: `swift test` (691 tests); the main window with three panes and a fold shared by all of them, by snapshot; the window and pane commands run to completion under the development hooks. | 157 | - Checked: `swift test` (691 tests); the main window with three panes and a fold shared by all of them, by snapshot; the window and pane commands run to completion under the development hooks. |
| 158 | |||
| 159 | ## Review | ||
| 160 | |||
| 161 | A fresh review of the branch found, and the fix pass closed: a nested split's inner divider resized the outer split (splits are now keyed by the two panes either side of the divider, with a test); the main window had no close-time cleanup, so reopening it drove a stale model (it now registers a fresh model on appear and releases its panes on disappear); the editor window's app commands did nothing with the main window closed (it reopens it first, and a request made before the window appeared runs when it does); narrowing and sparse trees left other views' carets in hidden text, and a view taking focus kept such a caret (every view's caret is moved, and a view taking focus runs the selection check); the palette and Quick Open acted on the main window's pane when opened from an editor window (they act on the pane that had the focus when they opened); the empty-pane placeholder left the keyboard with another pane; `WindowModel.closeAll` emptied the panes under views still on screen. | ||
| 162 | |||
| 163 | Deferred, minor: `kill` and `showPrevious` may fall back to a buffer another pane already shows (Emacs prefers one not visible); a split's new view starts at the top rather than at the point, and `truncatesLines` is per view and not copied to a new view; detached text views keep observing key-window changes (pre-existing, now common); `Theme.focusedLayouts` can keep a released primary view's id; `previousSelection` is per editor, so the first caret fix after switching views may jump the wrong way; `.onChange(of: session.path)` runs the sync-conflict scan on every focus change between panes showing different files. | ||