Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⌃+Tab and ^⇧+Tab keyboard shortcuts to cycle between window tabs #1777

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CodeEdit/CodeEditApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct CodeEditApp: App {
AboutWindow()

SettingsWindow()
.commands {
CodeEditCommands()
}
}
.commands {
CodeEditCommands()
}
.environment(\.settings, settings.preferences) // Add settings to each window environment
}
Expand Down
33 changes: 33 additions & 0 deletions CodeEdit/Features/WindowCommands/WindowCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct WindowCommands: Commands {
@Environment(\.openWindow)
var openWindow

@State var windowController: CodeEditWindowController?

var body: some Commands {
CommandGroup(replacing: .singleWindowList) {
Button("Welcome to CodeEdit") {
Expand All @@ -28,5 +30,36 @@ struct WindowCommands: Commands {
}
.keyboardShortcut("3", modifiers: [.shift, .command])
}

CommandGroup(replacing: .windowArrangement) {
Button("Show Previous Window Tab") {
NSApp.sendAction(#selector(NSWindow.selectPreviousTab), to: nil, from: nil)
}
.keyboardShortcut(.tab, modifiers: [.control, .shift])
.disabled(windowController?.window?.tabbedWindows == nil)
.onReceive(NSApp.publisher(for: \.keyWindow)) { window in
windowController = window?.windowController as? CodeEditWindowController
}

Button("Show Next Window Tab") {
NSApp.sendAction(#selector(NSWindow.selectNextTab), to: nil, from: nil)
}
.keyboardShortcut(.tab, modifiers: [.control])
.disabled(windowController?.window?.tabbedWindows == nil)
.onReceive(NSApp.publisher(for: \.keyWindow)) { window in
windowController = window?.windowController as? CodeEditWindowController
}

Button("Merge All Windows") {
NSApp.sendAction(#selector(NSWindow.mergeAllWindows), to: nil, from: nil)
}
// Only enable if we have more than one document open and all the windows are not merged
.disabled(shouldDisableMergeAll())
}
}

private func shouldDisableMergeAll() -> Bool {
// TODO: WINDOWS COUNT IS INCORRECT
return NSApplication.shared.windows.count <= (SceneID.allCases.count + 1)
}
}
Loading