Skip to content

Commit 5aff25f

Browse files
committed
extension and menu bar
1 parent a09eaf7 commit 5aff25f

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
58F2EB1E292FB954004A9BDE /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 58F2EB1D292FB954004A9BDE /* Sparkle */; };
249249
58FD7608291EA1CB0051D6E4 /* QuickActionsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD7605291EA1CB0051D6E4 /* QuickActionsViewModel.swift */; };
250250
58FD7609291EA1CB0051D6E4 /* QuickActionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD7607291EA1CB0051D6E4 /* QuickActionsView.swift */; };
251+
5994B6DA2BD6B408006A4C5F /* EditorTabSwitchExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5994B6D92BD6B408006A4C5F /* EditorTabSwitchExtension.swift */; };
251252
5B241BF32B6DDBFF0016E616 /* IgnorePatternListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B241BF22B6DDBFF0016E616 /* IgnorePatternListItemView.swift */; };
252253
5B698A0A2B262FA000DE9392 /* SearchSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B698A092B262FA000DE9392 /* SearchSettingsView.swift */; };
253254
5B698A0D2B26327800DE9392 /* SearchSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B698A0C2B26327800DE9392 /* SearchSettings.swift */; };
@@ -810,6 +811,7 @@
810811
58F2EAE1292FB2B0004A9BDE /* SoftwareUpdater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SoftwareUpdater.swift; sourceTree = "<group>"; };
811812
58FD7605291EA1CB0051D6E4 /* QuickActionsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickActionsViewModel.swift; sourceTree = "<group>"; };
812813
58FD7607291EA1CB0051D6E4 /* QuickActionsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickActionsView.swift; sourceTree = "<group>"; };
814+
5994B6D92BD6B408006A4C5F /* EditorTabSwitchExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorTabSwitchExtension.swift; sourceTree = "<group>"; };
813815
5B241BF22B6DDBFF0016E616 /* IgnorePatternListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IgnorePatternListItemView.swift; sourceTree = "<group>"; };
814816
5B698A092B262FA000DE9392 /* SearchSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSettingsView.swift; sourceTree = "<group>"; };
815817
5B698A0C2B26327800DE9392 /* SearchSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSettings.swift; sourceTree = "<group>"; };
@@ -2752,6 +2754,7 @@
27522754
6CA1AE942B46950000378EAB /* EditorInstance.swift */,
27532755
6CC9E4B129B5669900C97388 /* Environment+ActiveEditor.swift */,
27542756
6C092ED92A53A58600489202 /* EditorLayout+StateRestoration.swift */,
2757+
5994B6D92BD6B408006A4C5F /* EditorTabSwitchExtension.swift */,
27552758
);
27562759
path = Models;
27572760
sourceTree = "<group>";
@@ -3475,6 +3478,7 @@
34753478
581550CF29FBD30400684881 /* StandardTableViewCell.swift in Sources */,
34763479
B62AEDB82A1FE2DC009A9F52 /* UtilityAreaOutputView.swift in Sources */,
34773480
B67DB0FC2AFDF71F002DC647 /* IconToggleStyle.swift in Sources */,
3481+
5994B6DA2BD6B408006A4C5F /* EditorTabSwitchExtension.swift in Sources */,
34783482
587B9E5C29301D8F00AC7927 /* Parameters.swift in Sources */,
34793483
61538B932B11201900A88846 /* String+Character.swift in Sources */,
34803484
613DF55E2B08DD5D00E9D902 /* FileHelper.swift in Sources */,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// EditorTabSwitchExtension.swift
3+
// CodeEdit
4+
//
5+
// Created by Roscoe Rubin-Rottenberg on 4/22/24.
6+
//
7+
8+
import Foundation
9+
10+
extension Editor {
11+
func selectNextTab() {
12+
guard let currentTab = selectedTab, let currentIndex = tabs.firstIndex(of: currentTab) else { return }
13+
let nextIndex = tabs.index(after: currentIndex)
14+
if nextIndex < tabs.endIndex {
15+
selectedTab = tabs[nextIndex]
16+
} else {
17+
// Wrap around to the first tab if it's the last one
18+
selectedTab = tabs.first
19+
}
20+
}
21+
22+
func selectPreviousTab() {
23+
guard let currentTab = selectedTab, let currentIndex = tabs.firstIndex(of: currentTab) else { return }
24+
let previousIndex = tabs.index(before: currentIndex)
25+
if previousIndex >= tabs.startIndex {
26+
selectedTab = tabs[previousIndex]
27+
} else {
28+
// Wrap around to the last tab if it's the first one
29+
selectedTab = tabs.last
30+
}
31+
}
32+
}

CodeEdit/Features/Editor/TabBar/Tabs/Views/EditorTabs.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,6 @@ struct EditorTabs: View {
273273
}
274274
}
275275
}
276-
private func selectNextTab() {
277-
guard let currentIndex = openedTabs.firstIndex(of: editor.selectedTab?.file.id ?? "") else { return }
278-
let nextIndex = (currentIndex + 1) % openedTabs.count // Wraps around to the first tab if it's the last one
279-
editor.selectedTab = editor.tabs.first { $0.file.id == openedTabs[nextIndex] }
280-
}
281-
282-
private func selectPreviousTab() {
283-
guard let currentIndex = openedTabs.firstIndex(of: editor.selectedTab?.file.id ?? ""), !openedTabs.isEmpty else { return }
284-
let previousIndex = (currentIndex - 1 + openedTabs.count) % openedTabs.count // Wraps around to the last tab if it's the first one
285-
editor.selectedTab = editor.tabs.first { $0.file.id == openedTabs[previousIndex] }
286-
}
287276

288277
// swiftlint:enable function_body_length cyclomatic_complexity
289278

@@ -398,17 +387,6 @@ struct EditorTabs: View {
398387
EditorTabBarNativeInactiveBackground()
399388
}
400389
}
401-
// keyboard shortcuts to go to next and previous tabs
402-
Button(action: selectNextTab) {
403-
EmptyView()
404-
}
405-
.hidden()
406-
.keyboardShortcut("]", modifiers: [.command, .shift])
407-
Button(action: selectPreviousTab) {
408-
EmptyView()
409-
}
410-
.hidden()
411-
.keyboardShortcut("[", modifiers: [.command, .shift])
412390
}
413391
.background {
414392
if tabBarStyle == .native {
@@ -436,7 +414,6 @@ struct EditorTabs: View {
436414
}
437415
}
438416
}
439-
440417
}
441418

442419
private struct EditorTabOnDropDelegate: DropDelegate {

CodeEdit/Features/WindowCommands/NavigateCommands.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,20 @@ struct NavigateCommands: Commands {
3939
Divider()
4040

4141
}
42-
4342
Group {
4443
Button("Show Previous Tab") {
45-
44+
editor?.selectPreviousTab()
4645
}
47-
.disabled(true)
46+
.keyboardShortcut("{", modifiers: [.command])
47+
.disabled(editor?.tabs.count ?? 0 <= 1) // Disable if there's one or no tabs
4848

4949
Button("Show Next Tab") {
50-
50+
editor?.selectNextTab()
5151
}
52-
.disabled(true)
53-
52+
.keyboardShortcut("}", modifiers: [.command])
53+
.disabled(editor?.tabs.count ?? 0 <= 1) // Disable if there's one or no tabs
54+
}
55+
Group {
5456
Divider()
5557

5658
Button("Go Forward") {
@@ -62,6 +64,7 @@ struct NavigateCommands: Commands {
6264
editor?.goBackInHistory()
6365
}
6466
.disabled(!(editor?.canGoBackInHistory ?? false))
67+
6568
}
6669
.disabled(editor == nil)
6770
}

0 commit comments

Comments
 (0)