Skip to content

Commit

Permalink
New editors open first tab as a temporary tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
austincondiff committed Mar 11, 2024
1 parent d571c73 commit a02bf0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CodeEdit/Features/Editor/Models/Editor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,34 @@ final class Editor: ObservableObject, Identifiable {

init() {
self.tabs = []
self.temporaryTab = nil
self.parent = nil
}

init(
files: OrderedSet<CEWorkspaceFile> = [],
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<Tab> = [],
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.
Expand Down
15 changes: 8 additions & 7 deletions CodeEdit/Features/Editor/Models/EditorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit a02bf0b

Please sign in to comment.