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 {
3131struct BufferTabs: View {
3232 let session: DocumentSession
3333 let pane: EditorPane
34 let close: (String) -> Void
3435 @Environment(\.orgTheme) private var theme
3536
3637 var body: some View {
@@ -55,7 +56,7 @@ struct BufferTabs: View {
5556 .accessibilityAddTraits(current ? [.isButton, .isSelected] : .isButton)
5657 .accessibilityAction { session.open(path, in: pane) }
5758 Button {
58 if UnsavedChanges.resolve(session, paths: [path]) { session.kill(path) }
59 close(path)
5960 } label: {
6061 Image(systemName: session.dirtyPaths.contains(path) ? "circle.fill" : "xmark")
6162 .font(.system(size: session.dirtyPaths.contains(path) ? 6 : 9, weight: .semibold))
Sources/Orgstar/ContentView.swift +6 −11
@@ -137,14 +137,7 @@ struct ContentView: View {
137137
138138 /// Gives the focused pane's text view the keyboard, after a pane command moved the focus.
139139 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)
148141 }
149142 /// Carets of restored buffers, shown when each first shows.
150143 @State private var pendingCarets: [String: Int] = [:]
@@ -988,11 +981,13 @@ struct ContentView: View {
988981 case "app.buffer.previous": session.cycle(-1)
989982 case "app.buffer.last": session.showPrevious()
990983 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 {
992989 NSApp.keyWindow?.performClose(nil)
993 return
994990 }
995 if UnsavedChanges.resolve(session) { session.kill(path) }
996991 case "app.buffer.kill-others":
997992 let others = session.openPaths.filter { $0 != session.path }
998993 if UnsavedChanges.resolve(session, paths: others) { others.forEach(session.kill) }
Sources/Orgstar/PaneLayoutView.swift +1 −1
@@ -73,7 +73,7 @@ struct PaneCell: View {
7373
7474 var body: some View {
7575 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) } }
7777 if pane.path != nil {
7878 PaneView(pane: pane, session: session, commands: commands, settings: commands.editorSettings, onAppCommand: onAppCommand)
7979 } else {
Sources/Orgstar/WindowModel.swift +31
@@ -45,6 +45,37 @@ final class WindowModel: Identifiable {
4545 if focused == id { focus(rest.panes[0]) }
4646 }
4747
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
4879 /// Removes every pane but the focused one.
4980 func closeOthers() {
5081 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
148148
149149Switch 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.
150150
151Close 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.
151Close 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.
152152
153153When 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.
154154
@@ -169,7 +169,7 @@ These names show in the window title, the tab bar and Switch to Buffer.
169169View ▸ 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=.
170170
171171- 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.
173173
174174* Searching your notes
175175