Commit 0c25067ef4
0c25067ef4c1da0c645e93021f44e58c09444d3f
parent: 1ba1d7a952
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-13 04:18 UTC
Closing a pane's last tab closes the pane
With other panes in the window, ⌘W or × on a pane's only tab closes the pane
instead of leaving it empty, and closes the buffer only when no other pane
shows it. ⌘W on an empty pane closes the pane, not the window.
Layout: unified · split
Sources/Orgstar/BufferTabs.swift
+2 −1
| @@ -31,6 +31,7 @@ struct PaneDivider: View { |
| 31 | 31 | struct BufferTabs: View { |
| 32 | 32 | let session: DocumentSession |
| 33 | 33 | let pane: EditorPane |
| 34 | let close: (String) -> Void |
| 34 | 35 | @Environment(\.orgTheme) private var theme |
| 35 | 36 | |
| 36 | 37 | var body: some View { |
| @@ -55,7 +56,7 @@ struct BufferTabs: View { |
| 55 | 56 | .accessibilityAddTraits(current ? [.isButton, .isSelected] : .isButton) |
| 56 | 57 | .accessibilityAction { session.open(path, in: pane) } |
| 57 | 58 | Button { |
| 58 | | if UnsavedChanges.resolve(session, paths: [path]) { session.kill(path) } |
| 59 | close(path) |
| 59 | 60 | } label: { |
| 60 | 61 | Image(systemName: session.dirtyPaths.contains(path) ? "circle.fill" : "xmark") |
| 61 | 62 | .font(.system(size: session.dirtyPaths.contains(path) ? 6 : 9, weight: .semibold)) |
Sources/Orgstar/ContentView.swift
+6 −11
| @@ -137,14 +137,7 @@ struct ContentView: View { |
| 137 | 137 | |
| 138 | 138 | /// Gives the focused pane's text view the keyboard, after a pane command moved the focus. |
| 139 | 139 | private func focusPane(_ window: WindowModel) { |
| 140 | | let pane = window.focusedPane |
| 141 | | session.focused = pane |
| 142 | | if let path = pane.path, let textView = commands.store.textView(for: pane.id, path: path) { |
| 143 | | textView.window?.makeFirstResponder(textView) |
| 144 | | commands.editor = commands.store.editor(for: path) |
| 145 | | } else { |
| 146 | | commands.editor = nil |
| 147 | | } |
| 140 | window.activate(commands) |
| 148 | 141 | } |
| 149 | 142 | /// Carets of restored buffers, shown when each first shows. |
| 150 | 143 | @State private var pendingCarets: [String: Int] = [:] |
| @@ -988,11 +981,13 @@ struct ContentView: View { |
| 988 | 981 | case "app.buffer.previous": session.cycle(-1) |
| 989 | 982 | case "app.buffer.last": session.showPrevious() |
| 990 | 983 | case "app.buffer.kill": |
| 991 | | guard let path = session.path else { |
| 984 | if let window = paneWindow, window.paneCount > 1 { |
| 985 | window.closeTab(session.path, in: window.focusedPane, commands: commands) |
| 986 | } else if let path = session.path { |
| 987 | if UnsavedChanges.resolve(session) { session.kill(path) } |
| 988 | } else { |
| 992 | 989 | NSApp.keyWindow?.performClose(nil) |
| 993 | | return |
| 994 | 990 | } |
| 995 | | if UnsavedChanges.resolve(session) { session.kill(path) } |
| 996 | 991 | case "app.buffer.kill-others": |
| 997 | 992 | let others = session.openPaths.filter { $0 != session.path } |
| 998 | 993 | if UnsavedChanges.resolve(session, paths: others) { others.forEach(session.kill) } |
Sources/Orgstar/PaneLayoutView.swift
+1 −1
| @@ -73,7 +73,7 @@ struct PaneCell: View { |
| 73 | 73 | |
| 74 | 74 | var body: some View { |
| 75 | 75 | VStack(spacing: 0) { |
| 76 | | if showTabBar { BufferTabs(session: session, pane: pane) } |
| 76 | if showTabBar { BufferTabs(session: session, pane: pane) { window.closeTab($0, in: pane, commands: commands) } } |
| 77 | 77 | if pane.path != nil { |
| 78 | 78 | PaneView(pane: pane, session: session, commands: commands, settings: commands.editorSettings, onAppCommand: onAppCommand) |
| 79 | 79 | } else { |
Sources/Orgstar/WindowModel.swift
+31
| @@ -45,6 +45,37 @@ final class WindowModel: Identifiable { |
| 45 | 45 | if focused == id { focus(rest.panes[0]) } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | /// Closes `path`'s tab in `pane`, or the empty pane when `path` is nil. With other panes in |
| 49 | /// the window and no other tab here, the pane closes too, and the buffer closes only if no |
| 50 | /// other pane shows it. False when unsaved changes kept it open. |
| 51 | @discardableResult |
| 52 | func closeTab(_ path: String?, in pane: EditorPane, commands: AppCommands) -> Bool { |
| 53 | let closesPane = paneCount > 1 && pane.shown.allSatisfy { $0 == path } |
| 54 | let elsewhere = path.map { path in session.panes.contains { $0 !== pane && $0.shown.contains(path) } } ?? true |
| 55 | if let path, !(closesPane && elsewhere) { |
| 56 | guard UnsavedChanges.resolve(session, paths: [path]) else { return false } |
| 57 | } |
| 58 | if closesPane { |
| 59 | commands.store.releasePane(pane.id) |
| 60 | close(pane.id) |
| 61 | activate(commands) |
| 62 | } |
| 63 | if let path, !(closesPane && elsewhere) { session.kill(path) } |
| 64 | return true |
| 65 | } |
| 66 | |
| 67 | /// Gives the focused pane's text view the keyboard, after a pane command moved the focus. |
| 68 | func activate(_ commands: AppCommands) { |
| 69 | let pane = focusedPane |
| 70 | session.focused = pane |
| 71 | if let path = pane.path, let textView = commands.store.textView(for: pane.id, path: path) { |
| 72 | textView.window?.makeFirstResponder(textView) |
| 73 | commands.editor = commands.store.editor(for: path) |
| 74 | } else { |
| 75 | commands.editor = nil |
| 76 | } |
| 77 | } |
| 78 | |
| 48 | 79 | /// Removes every pane but the focused one. |
| 49 | 80 | func closeOthers() { |
| 50 | 81 | for id in layout.panes where id != focused { close(id) } |
docs/manual/guide/01-files-and-folders.org
+2 −2
| @@ -148,7 +148,7 @@ Menu shortcuts (=⇧⌘]=, =⌘W= and the others) work in every preset. The Doom |
| 148 | 148 | |
| 149 | 149 | Switch to Buffer asks in the echo area. The choices are the open buffers, most recently shown first, with the current buffer last. Type to narrow them, =Tab= to complete the top choice, =Return= to switch, =Escape= to cancel. |
| 150 | 150 | |
| 151 | | Close Buffer closes the current buffer and shows the buffer you showed before it. With no buffer open, =⌘W= closes the window. In other windows (Agenda, Board and so on) =⌘W= closes that window. File ▸ Close Window (=⇧⌘W=) closes the window in front. |
| 151 | Close Buffer closes the current buffer and shows the buffer you showed before it. With no buffer open, =⌘W= closes the window. In a window split into panes, closing the last tab of a pane closes the pane; its buffer stays open when another pane shows it. In other windows (Agenda, Board and so on) =⌘W= closes that window. File ▸ Close Window (=⇧⌘W=) closes the window in front. |
| 152 | 152 | |
| 153 | 153 | When you close buffers with unsaved edits, what happens depends on the save mode (see /Saving/ below): in automatic mode they are saved first; in explicit mode orgstar asks =Save=, =Don't Save= or =Cancel= (=Save All= for several files). A buffer whose save fails or conflicts stays open. |
| 154 | 154 | |
| @@ -169,7 +169,7 @@ These names show in the window title, the tab bar and Switch to Buffer. |
| 169 | 169 | View ▸ Show Tab Bar shows a row of tabs above each pane, one per buffer that pane has shown, in the order it first showed them. It is off by default; the setting is =tab-bar= in =config.toml=. |
| 170 | 170 | |
| 171 | 171 | - Click a tab to show its buffer. Hover to see the file's full path. |
| 172 | | - Click =×= to close a buffer, in every pane. A dot replaces the =×= while the buffer has unsaved edits; clicking it also closes the buffer, with the same unsaved-changes handling as Close Buffer. |
| 172 | - Click =×= to close a buffer, in every pane. On a pane's last tab, with other panes in the window, it closes the pane as well, as Close Buffer does. A dot replaces the =×= while the buffer has unsaved edits; clicking it also closes the buffer, with the same unsaved-changes handling as Close Buffer. |
| 173 | 173 | |
| 174 | 174 | * Searching your notes |
| 175 | 175 | |