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

keyboard shortcut for tab switching #1677

Merged
merged 3 commits into from
Apr 22, 2024
Merged
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
4 changes: 4 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
58F2EB1E292FB954004A9BDE /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 58F2EB1D292FB954004A9BDE /* Sparkle */; };
58FD7608291EA1CB0051D6E4 /* QuickActionsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD7605291EA1CB0051D6E4 /* QuickActionsViewModel.swift */; };
58FD7609291EA1CB0051D6E4 /* QuickActionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD7607291EA1CB0051D6E4 /* QuickActionsView.swift */; };
5994B6DA2BD6B408006A4C5F /* EditorTabSwitchExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5994B6D92BD6B408006A4C5F /* EditorTabSwitchExtension.swift */; };
5B241BF32B6DDBFF0016E616 /* IgnorePatternListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B241BF22B6DDBFF0016E616 /* IgnorePatternListItemView.swift */; };
5B698A0A2B262FA000DE9392 /* SearchSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B698A092B262FA000DE9392 /* SearchSettingsView.swift */; };
5B698A0D2B26327800DE9392 /* SearchSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B698A0C2B26327800DE9392 /* SearchSettings.swift */; };
Expand Down Expand Up @@ -810,6 +811,7 @@
58F2EAE1292FB2B0004A9BDE /* SoftwareUpdater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SoftwareUpdater.swift; sourceTree = "<group>"; };
58FD7605291EA1CB0051D6E4 /* QuickActionsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickActionsViewModel.swift; sourceTree = "<group>"; };
58FD7607291EA1CB0051D6E4 /* QuickActionsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickActionsView.swift; sourceTree = "<group>"; };
5994B6D92BD6B408006A4C5F /* EditorTabSwitchExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorTabSwitchExtension.swift; sourceTree = "<group>"; };
5B241BF22B6DDBFF0016E616 /* IgnorePatternListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IgnorePatternListItemView.swift; sourceTree = "<group>"; };
5B698A092B262FA000DE9392 /* SearchSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSettingsView.swift; sourceTree = "<group>"; };
5B698A0C2B26327800DE9392 /* SearchSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSettings.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2752,6 +2754,7 @@
6CA1AE942B46950000378EAB /* EditorInstance.swift */,
6CC9E4B129B5669900C97388 /* Environment+ActiveEditor.swift */,
6C092ED92A53A58600489202 /* EditorLayout+StateRestoration.swift */,
5994B6D92BD6B408006A4C5F /* EditorTabSwitchExtension.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -3475,6 +3478,7 @@
581550CF29FBD30400684881 /* StandardTableViewCell.swift in Sources */,
B62AEDB82A1FE2DC009A9F52 /* UtilityAreaOutputView.swift in Sources */,
B67DB0FC2AFDF71F002DC647 /* IconToggleStyle.swift in Sources */,
5994B6DA2BD6B408006A4C5F /* EditorTabSwitchExtension.swift in Sources */,
587B9E5C29301D8F00AC7927 /* Parameters.swift in Sources */,
61538B932B11201900A88846 /* String+Character.swift in Sources */,
613DF55E2B08DD5D00E9D902 /* FileHelper.swift in Sources */,
Expand Down
32 changes: 32 additions & 0 deletions CodeEdit/Features/Editor/Models/EditorTabSwitchExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// EditorTabSwitchExtension.swift
// CodeEdit
//
// Created by Roscoe Rubin-Rottenberg on 4/22/24.
//

import Foundation

extension Editor {
func selectNextTab() {
guard let currentTab = selectedTab, let currentIndex = tabs.firstIndex(of: currentTab) else { return }
let nextIndex = tabs.index(after: currentIndex)
if nextIndex < tabs.endIndex {
selectedTab = tabs[nextIndex]
} else {
// Wrap around to the first tab if it's the last one
selectedTab = tabs.first
}
}

func selectPreviousTab() {
guard let currentTab = selectedTab, let currentIndex = tabs.firstIndex(of: currentTab) else { return }
let previousIndex = tabs.index(before: currentIndex)
if previousIndex >= tabs.startIndex {
selectedTab = tabs[previousIndex]
} else {
// Wrap around to the last tab if it's the first one
selectedTab = tabs.last
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ struct EditorTabs: View {
CGFloat(140)
)
}

// Disable the rule because this function is implementing the drag gesture and its animations.
// It is fairly complicated, so ignore the function body length limitation for now.
// swiftlint:disable function_body_length cyclomatic_complexity
Expand Down
14 changes: 8 additions & 6 deletions CodeEdit/Features/WindowCommands/NavigateCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ struct NavigateCommands: Commands {
Divider()

}

Group {
Button("Show Previous Tab") {

editor?.selectPreviousTab()
}
.disabled(true)
.keyboardShortcut("{", modifiers: [.command])
.disabled(editor?.tabs.count ?? 0 <= 1) // Disable if there's one or no tabs

Button("Show Next Tab") {

editor?.selectNextTab()
}
.disabled(true)

.keyboardShortcut("}", modifiers: [.command])
.disabled(editor?.tabs.count ?? 0 <= 1) // Disable if there's one or no tabs
}
Group {
Divider()

Button("Go Forward") {
Expand Down
Loading