Skip to content

Commit fddb150

Browse files
Fixed close tab and close window shortcut (#1381)
* Fixed close tab and close window shortcut * Replace .hidden modifier with .opacity modifier * Close current tab updates * Removed unnecessary modifier
1 parent 089859a commit fddb150

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

CodeEdit/Features/Documents/Controllers/CodeEditWindowController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
299299
}
300300
}
301301
}
302+
303+
@IBAction func closeCurrentTab(_ sender: Any) {
304+
workspace?.tabManager.activeTabGroup.closeCurrentTab()
305+
}
302306
}
303307

304308
extension CodeEditWindowController {

CodeEdit/Features/Tabs/TabGroup/TabGroupData.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ final class TabGroupData: ObservableObject, Identifiable {
114114
}
115115
}
116116

117+
/// Closes the currently opened tab in the tab group.
118+
func closeCurrentTab() {
119+
guard let selectedTab = selected else {
120+
return
121+
}
122+
123+
closeTab(item: selectedTab)
124+
}
125+
117126
/// Opens a tab in the tabgroup.
118127
/// If a tab for the item already exists, it is used instead.
119128
/// - Parameters:

CodeEdit/Features/Tabs/Views/TabBarItemView.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,6 @@ struct TabBarItemView: View {
163163
.padding(.horizontal, tabBarStyle == .native ? 28 : 23)
164164
.overlay {
165165
ZStack {
166-
if isActive {
167-
// Close Tab Shortcut:
168-
// Using an invisible button to contain the keyboard shortcut is simply
169-
// because the keyboard shortcut has an unexpected bug when working with
170-
// custom buttonStyle. This is an workaround and it works as expected.
171-
Button(
172-
action: closeAction,
173-
label: { EmptyView() }
174-
)
175-
.frame(width: 0, height: 0)
176-
.keyboardShortcut("w", modifiers: [.command])
177-
.hidden()
178-
}
179166
// Switch Tab Shortcut:
180167
// Using an invisible button to contain the keyboard shortcut is simply
181168
// because the keyboard shortcut has an unexpected bug when working with

CodeEdit/Features/WindowCommands/FileCommands.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ struct FileCommands: Commands {
3737

3838
CommandGroup(replacing: .saveItem) {
3939
Button("Close Tab") {
40-
NSApp.sendAction(#selector(NSWindow.close), to: nil, from: nil)
40+
NSApp.sendAction(#selector(CodeEditWindowController.closeCurrentTab(_:)), to: nil, from: nil)
4141
}
4242
.keyboardShortcut("w")
4343

4444
Button("Close Editor") {
45-
45+
NSApp.sendAction(#selector(NSWindow.close), to: nil, from: nil)
4646
}
4747
.keyboardShortcut("w", modifiers: [.control, .shift, .command])
4848

0 commit comments

Comments
 (0)