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

Added ability to focus a single editor #1414

Merged
merged 3 commits into from
Aug 29, 2023
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
12 changes: 12 additions & 0 deletions CodeEdit/Features/SplitView/Model/SplitViewData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ final class SplitViewData: ObservableObject {
}
}

func getTabGroup(with id: TabGroupData.ID) -> TabGroup? {
for tabgroup in tabgroups {
if case .one(let tabGroupData) = tabgroup {
if tabGroupData.id == id {
return tabgroup
}
}
}

return nil
}

/// Flattens the splitviews.
func flatten() {
for index in tabgroups.indices {
Expand Down
3 changes: 3 additions & 0 deletions CodeEdit/Features/Tabs/Models/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class TabManager: ObservableObject {
/// Collection of all the tabgroups.
@Published var tabGroups: TabGroup

@Published var isFocusingActiveTabGroup: Bool

/// The TabGroup with active focus.
@Published var activeTabGroup: TabGroupData {
didSet {
Expand All @@ -36,6 +38,7 @@ class TabManager: ObservableObject {
self.activeTabGroup = tab
self.activeTabGroupHistory.prepend { [weak tab] in tab }
self.tabGroups = .horizontal(.init(.horizontal, tabgroups: [.one(tab)]))
self.isFocusingActiveTabGroup = false
switchToActiveTabGroup()
}

Expand Down
5 changes: 5 additions & 0 deletions CodeEdit/Features/Tabs/TabGroup/TabGroupData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ final class TabGroupData: ObservableObject, Identifiable {
parent?.closeTabGroup(with: id)
}

/// Gets the tabgroup.
func getTabGroup() -> TabGroup? {
return parent?.getTabGroup(with: id)
matthijseikelenboom marked this conversation as resolved.
Show resolved Hide resolved
}

/// Closes a tab in the tabgroup.
/// This will also write any changes to the file on disk and will add the tab to the tab history.
/// - Parameter item: the tab to close.
Expand Down
10 changes: 7 additions & 3 deletions CodeEdit/Features/Tabs/Views/TabBarAccessory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ struct TabBarAccessoryIcon: View {
static let iconFont = Font.system(size: 14, weight: .regular, design: .default)

private let icon: Image
private let isActive: Bool
private let action: () -> Void

init(icon: Image, action: @escaping () -> Void) {
init(icon: Image, isActive: Bool = false, action: @escaping () -> Void) {
self.icon = icon
self.isActive = isActive
self.action = action
}

var body: some View {
Button(
action: action,
label: { icon }
label: {
icon
}
)
.buttonStyle(.icon(size: 24))
.buttonStyle(.icon(isActive: isActive, size: 24))
}
}

Expand Down
32 changes: 28 additions & 4 deletions CodeEdit/Features/Tabs/Views/TabBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ struct TabBarView: View {
// MARK: Accessories

private var leadingAccessories: some View {
HStack(spacing: 2) {
HStack(spacing: 0) {
if let otherGroup = tabManager.tabGroups.findSomeTabGroup(except: tabgroup) {
TabBarAccessoryIcon(
icon: .init(systemName: "multiply"),
Expand All @@ -477,6 +477,28 @@ struct TabBarView: View {
}
)
.help("Close this Editor")
.disabled(tabManager.isFocusingActiveTabGroup)
.opacity(tabManager.isFocusingActiveTabGroup ? 0.5 : 1)

TabBarAccessoryIcon(
icon: .init(
systemName: tabManager.isFocusingActiveTabGroup
? "arrow.down.forward.and.arrow.up.backward"
: "arrow.up.left.and.arrow.down.right"
),
isActive: tabManager.isFocusingActiveTabGroup,
action: {
if !tabManager.isFocusingActiveTabGroup {
tabManager.activeTabGroup = tabgroup
}
tabManager.isFocusingActiveTabGroup.toggle()
}
)
.help(
tabManager.isFocusingActiveTabGroup
? "Unfocus this Editor"
: "Focus this Editor"
)

Divider()
.frame(height: 10)
Expand Down Expand Up @@ -547,7 +569,7 @@ struct TabBarView: View {
}
.foregroundColor(.secondary)
.buttonStyle(.plain)
.padding(.horizontal, 7)
.padding(.horizontal, 5)
.opacity(activeState != .inactive ? 1.0 : 0.5)
.frame(maxHeight: .infinity) // Fill out vertical spaces.
.background {
Expand All @@ -558,10 +580,10 @@ struct TabBarView: View {
}

private var trailingAccessories: some View {
HStack(spacing: 2) {
HStack(spacing: 0) {
splitviewButton
}
.padding(.horizontal, 10)
.padding(.horizontal, 7)
.opacity(activeState != .inactive ? 1.0 : 0.5)
.frame(maxHeight: .infinity) // Fill out vertical spaces.
.background {
Expand Down Expand Up @@ -595,6 +617,8 @@ struct TabBarView: View {
}
}
.buttonStyle(.icon)
.disabled(tabManager.isFocusingActiveTabGroup)
.opacity(tabManager.isFocusingActiveTabGroup ? 0.5 : 1)
}

func split(edge: Edge) {
Expand Down
23 changes: 14 additions & 9 deletions CodeEdit/WorkspaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ struct WorkspaceView: View {
VStack {
SplitViewReader { proxy in
SplitView(axis: .vertical) {
EditorView(tabgroup: tabManager.tabGroups, focus: $focusedEditor)
.collapsable()
.collapsed($debugAreaModel.isMaximized)
.frame(minHeight: 170 + 29 + 29)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.holdingPriority(.init(1))
.safeAreaInset(edge: .bottom, spacing: 0) {
StatusBarView(proxy: proxy)
}
EditorView(
tabgroup: tabManager.isFocusingActiveTabGroup
? tabManager.activeTabGroup.getTabGroup() ?? tabManager.tabGroups
: tabManager.tabGroups,
focus: $focusedEditor
)
.collapsable()
.collapsed($debugAreaModel.isMaximized)
.frame(minHeight: 170 + 29 + 29)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.holdingPriority(.init(1))
.safeAreaInset(edge: .bottom, spacing: 0) {
StatusBarView(proxy: proxy)
}
DebugAreaView()
.collapsable()
.collapsed($debugAreaModel.isCollapsed)
Expand Down