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

Fix visual issues with dragging AreaTabBar icons #1435

Merged
merged 3 commits into from
Sep 25, 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.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
2B7AC06B282452FB0082A5B8 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2B7AC06A282452FB0082A5B8 /* Media.xcassets */; };
2BE487EF28245162003F3F64 /* FinderSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE487EE28245162003F3F64 /* FinderSync.swift */; };
2BE487F428245162003F3F64 /* OpenWithCodeEdit.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2BE487EC28245162003F3F64 /* OpenWithCodeEdit.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
3026F50F2AC006C80061227E /* InspectorAreaViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */; };
30E6D0012A6E505200A58B20 /* NavigatorSidebarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */; };
3E0196732A3921AC002648D8 /* codeedit_shell_integration.zsh in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */; };
3E01967A2A392B45002648D8 /* codeedit_shell_integration.bash in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */; };
Expand Down Expand Up @@ -519,6 +520,7 @@
2BE487EC28245162003F3F64 /* OpenWithCodeEdit.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OpenWithCodeEdit.appex; sourceTree = BUILT_PRODUCTS_DIR; };
2BE487EE28245162003F3F64 /* FinderSync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderSync.swift; sourceTree = "<group>"; };
2BE487F028245162003F3F64 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectorAreaViewModel.swift; sourceTree = "<group>"; };
30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigatorSidebarViewModel.swift; sourceTree = "<group>"; };
3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.zsh; sourceTree = "<group>"; };
3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.bash; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1094,6 +1096,14 @@
path = OpenWithCodeEdit;
sourceTree = "<group>";
};
3026F50B2AC006A10061227E /* ViewModels */ = {
isa = PBXGroup;
children = (
3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
};
307AC4CB2ABABD9800163376 /* ViewModels */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2505,6 +2515,7 @@
B6EE988E27E8877C00CDD8AB /* InspectorArea */ = {
isa = PBXGroup;
children = (
3026F50B2AC006A10061227E /* ViewModels */,
B67660672AA972B000CD56B0 /* FileInspector */,
B67660662AA9726F00CD56B0 /* HistoryInspector */,
20EBB50B280C382800F3A5DA /* Models */,
Expand Down Expand Up @@ -2867,6 +2878,7 @@
587B9E8A29301D8F00AC7927 /* GitHubIssue.swift in Sources */,
EC0870F72A455F6400EB8692 /* ProjectNavigatorViewController+NSMenuDelegate.swift in Sources */,
6CAAF69429BCD78600A1F48A /* (null) in Sources */,
3026F50F2AC006C80061227E /* InspectorAreaViewModel.swift in Sources */,
6C82D6C629C012AD00495C54 /* NSApp+openWindow.swift in Sources */,
6C14CEB028777D3C001468FE /* FindNavigatorListViewController.swift in Sources */,
587B9E7F29301D8F00AC7927 /* GitHubUserRouter.swift in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct AreaTabBar<Tab: AreaTab>: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
.animation(.default, value: items)
}
.clipped()
.frame(maxWidth: .infinity, idealHeight: 27)
.fixedSize(horizontal: false, vertical: true)
}
Expand All @@ -66,6 +67,7 @@ struct AreaTabBar<Tab: AreaTab>: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
.animation(.default, value: items)
}
.clipped()
.frame(idealWidth: 40, maxHeight: .infinity)
.fixedSize(horizontal: true, vertical: false)
}
Expand Down Expand Up @@ -227,10 +229,8 @@ struct AreaTabBar<Tab: AreaTab>: View {
if isWithinBounds {
let changing = swapTabWidth - 1
draggingStartLocation! += direction == .previous ? -changing : changing
withAnimation {
tabOffsets[tab]! += direction == .previous ? changing : -changing
items.swapAt(currentIndex, swapIndex)
}
tabOffsets[tab]! += direction == .previous ? changing : -changing
items.swapAt(currentIndex, swapIndex)
}
}
// swiftlint: enable function_parameter_count
Expand Down Expand Up @@ -276,7 +276,7 @@ struct AreaTabBar<Tab: AreaTab>: View {
Rectangle()
.foregroundColor(.clear)
.onAppear {
self.tabWidth[tab] = geometry.size.width
self.tabWidth[tab] = (position == .top) ? geometry.size.width : geometry.size.height
self.tabLocations[tab] = geometry.frame(in: .global)
}
.onChange(of: geometry.frame(in: .global)) { newFrame in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
splitVC.addSplitViewItem(mainContent)

let inspectorView = SettingsInjector {
InspectorAreaView()
InspectorAreaView(viewModel: InspectorAreaViewModel())
.environmentObject(workspace)
.environmentObject(workspace.editorManager)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// InspectorAreaViewModel.swift
// CodeEdit
//
// Created by Abe Malla on 9/23/23.
//

import Foundation

class InspectorAreaViewModel: ObservableObject {
@Published var selectedTab: InspectorTab? = .file
/// The tab bar items in the Inspector
@Published var tabItems: [InspectorTab] = []

func setInspectorTab(tab newTab: InspectorTab) {
selectedTab = newTab
}
}
13 changes: 8 additions & 5 deletions CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ struct InspectorAreaView: View {
@EnvironmentObject private var workspace: WorkspaceDocument

@ObservedObject private var extensionManager = ExtensionManager.shared
@ObservedObject public var viewModel: InspectorAreaViewModel

@EnvironmentObject private var editorManager: EditorManager

@AppSettings(\.general.inspectorTabBarPosition)
var sidebarPosition: SettingsData.SidebarTabBarPosition

@State private var selection: InspectorTab? = .file
@State private var items: [InspectorTab] = [.file, .gitHistory]

init() {
items += extensionManager
init(viewModel: InspectorAreaViewModel) {
self.viewModel = viewModel

viewModel.tabItems = [.file, .gitHistory]
viewModel.tabItems += extensionManager
.extensions
.map { ext in
ext.availableFeatures.compactMap {
Expand Down Expand Up @@ -60,15 +63,15 @@ struct InspectorAreaView: View {
if sidebarPosition == .side {
HStack(spacing: 0) {
Divider()
AreaTabBar(items: $items, selection: $selection, position: sidebarPosition)
AreaTabBar(items: $viewModel.tabItems, selection: $selection, position: sidebarPosition)
}
}
}
.safeAreaInset(edge: .top, spacing: 0) {
if sidebarPosition == .top {
VStack(spacing: 0) {
Divider()
AreaTabBar(items: $items, selection: $selection, position: sidebarPosition)
AreaTabBar(items: $viewModel.tabItems, selection: $selection, position: sidebarPosition)
Divider()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Foundation

class NavigatorSidebarViewModel: ObservableObject {
@Published var selectedTab: NavigatorTab? = .project
var items: [NavigatorTab] = []
/// The tab bar items in the Navigator
@Published var tabItems: [NavigatorTab] = []

func setNavigatorTab(tab newTab: NavigatorTab) {
selectedTab = newTab
Expand Down
6 changes: 3 additions & 3 deletions CodeEdit/Features/NavigatorArea/Views/NavigatorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct NavigatorAreaView: View {
self.workspace = workspace
self.viewModel = viewModel

viewModel.items = [.project, .sourceControl, .search] +
viewModel.tabItems = [.project, .sourceControl, .search] +
extensionManager
.extensions
.map { ext in
Expand All @@ -44,7 +44,7 @@ struct NavigatorAreaView: View {
.safeAreaInset(edge: .leading, spacing: 0) {
if sidebarPosition == .side {
HStack(spacing: 0) {
AreaTabBar(items: $viewModel.items, selection: $viewModel.selectedTab, position: sidebarPosition)
AreaTabBar(items: $viewModel.tabItems, selection: $viewModel.selectedTab, position: sidebarPosition)
Divider()
}
}
Expand All @@ -53,7 +53,7 @@ struct NavigatorAreaView: View {
if sidebarPosition == .top {
VStack(spacing: 0) {
Divider()
AreaTabBar(items: $viewModel.items, selection: $viewModel.selectedTab, position: sidebarPosition)
AreaTabBar(items: $viewModel.tabItems, selection: $viewModel.selectedTab, position: sidebarPosition)
Divider()
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Features/WindowCommands/ViewCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ extension ViewCommands {

var body: some View {
Menu("Navigators", content: {
ForEach(Array(model.items.prefix(9).enumerated()), id: \.element) { index, tab in
ForEach(Array(model.tabItems.prefix(9).enumerated()), id: \.element) { index, tab in
Button(tab.title) {
model.setNavigatorTab(tab: tab)
}
Expand Down