diff --git a/CodeEdit/Features/Editor/Models/Editor.swift b/CodeEdit/Features/Editor/Models/Editor.swift index 2a494baa1..f04d33d42 100644 --- a/CodeEdit/Features/Editor/Models/Editor.swift +++ b/CodeEdit/Features/Editor/Models/Editor.swift @@ -64,29 +64,34 @@ final class Editor: ObservableObject, Identifiable { init() { self.tabs = [] + self.temporaryTab = nil self.parent = nil } init( files: OrderedSet = [], selectedTab: Tab? = nil, + temporaryTab: Tab? = nil, parent: SplitViewData? = nil ) { self.tabs = [] self.parent = parent files.forEach { openTab(file: $0) } self.selectedTab = selectedTab ?? (files.isEmpty ? nil : Tab(file: files.first!)) + self.temporaryTab = temporaryTab } init( files: OrderedSet = [], selectedTab: Tab? = nil, + temporaryTab: Tab? = nil, parent: SplitViewData? = nil ) { self.tabs = [] self.parent = parent files.forEach { openTab(file: $0.file) } self.selectedTab = selectedTab ?? tabs.first + self.temporaryTab = temporaryTab } /// Closes the editor. diff --git a/CodeEdit/Features/Editor/Models/EditorManager.swift b/CodeEdit/Features/Editor/Models/EditorManager.swift index 063e30a70..4330d2e2b 100644 --- a/CodeEdit/Features/Editor/Models/EditorManager.swift +++ b/CodeEdit/Features/Editor/Models/EditorManager.swift @@ -72,21 +72,22 @@ class EditorManager: ObservableObject { /// Flattens the splitviews. func flatten() { - if case .horizontal(let data) = editorLayout { - data.flatten() - } else if case .vertical(let data) = editorLayout { + switch editorLayout { + case .horizontal(let data), .vertical(let data): data.flatten() + default: + break } } /// Returns and array of flattened splitviews. func getFlattened() -> [Editor] { - if case .horizontal(let data) = editorLayout { - return data.getFlattened() - } else if case .vertical(let data) = editorLayout { + switch editorLayout { + case .horizontal(let data), .vertical(let data): return data.getFlattened() + default: + return [] } - return [] } /// Opens a new tab in a editor. diff --git a/CodeEdit/Features/Editor/TabBar/Views/EditorTabBarTrailingAccessories.swift b/CodeEdit/Features/Editor/TabBar/Views/EditorTabBarTrailingAccessories.swift index eb93488a1..f023729ca 100644 --- a/CodeEdit/Features/Editor/TabBar/Views/EditorTabBarTrailingAccessories.swift +++ b/CodeEdit/Features/Editor/TabBar/Views/EditorTabBarTrailingAccessories.swift @@ -69,7 +69,7 @@ struct EditorTabBarTrailingAccessories: View { func split(edge: Edge) { let newEditor: Editor if let tab = editor.selectedTab { - newEditor = .init(files: [tab]) + newEditor = .init(files: [tab], temporaryTab: tab) } else { newEditor = .init() }