Skip to content

Commit

Permalink
Invalidating flattenedEditors cache when editors change.
Browse files Browse the repository at this point in the history
  • Loading branch information
austincondiff committed Mar 7, 2024
1 parent f4f257a commit d571c73
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CodeEdit/Features/Editor/Models/EditorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EditorManager: ObservableObject {
var cancellable: AnyCancellable?

// This caching mechanism is a temporary solution and is not optimized
var updateCachedFlattenedEditors: Bool = true
@Published var updateCachedFlattenedEditors: Bool = true
var cachedFlettenedEditors: [Editor] = []
var flattenedEditors: [Editor] {
if updateCachedFlattenedEditors {
Expand Down Expand Up @@ -120,6 +120,7 @@ class EditorManager: ObservableObject {

flatten()
objectWillChange.send()
updateCachedFlattenedEditors = true
}

/// Set a new active editor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct EditorPathBarView: View {
}
}
}
.padding(.horizontal, shouldShowTabBar ? file == nil ? 10 : 4 : 0)
.padding(.horizontal, shouldShowTabBar ? (file == nil ? 10 : 4) : 0)
.safeAreaInset(edge: .leading, spacing: 0) {
if !shouldShowTabBar {
EditorTabBarLeadingAccessories()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct EditorTabBarTrailingAccessories: View {
newEditor = .init()
}
splitEditor(edge, newEditor)
editorManager.updateCachedFlattenedEditors = true
editorManager.activeEditor = newEditor
}
}
Expand Down
24 changes: 12 additions & 12 deletions CodeEdit/Features/Editor/Views/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ struct EditorView: View {

@EnvironmentObject private var editorManager: EditorManager

var shouldShowTabBar: Bool {
return navigationStyle == .openInTabs
|| editorManager.flattenedEditors.contains { editor in
(editor.temporaryTab == nil && !editor.tabs.isEmpty)
|| (editor.temporaryTab != nil && editor.tabs.count > 1)
var body: some View {
var shouldShowTabBar: Bool {
return navigationStyle == .openInTabs
|| editorManager.flattenedEditors.contains { editor in
(editor.temporaryTab == nil && !editor.tabs.isEmpty)
|| (editor.temporaryTab != nil && editor.tabs.count > 1)
}
}
}

var editorInsetAmount: Double {
let tabBarHeight = shouldShowTabBar ? (EditorTabBarView.height + 1) : 0
let pathBarHeight = showEditorPathBar ? (EditorPathBarView.height + 1) : 0
return tabBarHeight + pathBarHeight
}
var editorInsetAmount: Double {
let tabBarHeight = shouldShowTabBar ? (EditorTabBarView.height + 1) : 0
let pathBarHeight = showEditorPathBar ? (EditorPathBarView.height + 1) : 0
return tabBarHeight + pathBarHeight
}

var body: some View {
VStack {
if let selected = editor.selectedTab {
WorkspaceCodeFileView(
Expand Down

0 comments on commit d571c73

Please sign in to comment.