Skip to content

Commit 4282ddd

Browse files
committed
Improve property naming and readability
1 parent eb27fa1 commit 4282ddd

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,25 @@ struct EditorTabView: View {
5757

5858
@EnvironmentObject private var editor: Editor
5959

60-
/// The item associated with the current tab.
60+
/// The file item associated with the current tab.
6161
///
6262
/// You can get tab-related information from here, like `label`, `icon`, etc.
63-
private let item: CEWorkspaceFile
63+
private let tabFile: CEWorkspaceFile
6464

6565
var index: Int
6666

6767
private var isTemporary: Bool {
68-
editor.temporaryTab?.file == item
68+
editor.temporaryTab?.file == tabFile
6969
}
7070

7171
/// Is the current tab the active tab.
7272
private var isActive: Bool {
73-
item == editor.selectedTab?.file
73+
tabFile == editor.selectedTab?.file
7474
}
7575

7676
/// Is the current tab being dragged.
7777
private var isDragging: Bool {
78-
draggingTabId == item.id
78+
draggingTabId == tabFile.id
7979
}
8080

8181
/// Is the current tab being held (by click and hold, not drag).
@@ -89,9 +89,9 @@ struct EditorTabView: View {
8989
private func switchAction() {
9090
// Only set the `selectedId` when they are not equal to avoid performance issue for now.
9191
editorManager.activeEditor = editor
92-
if editor.selectedTab?.file != item {
93-
let tabItem = EditorInstance(file: item)
94-
editor.setSelectedTab(item)
92+
if editor.selectedTab?.file != tabFile {
93+
let tabItem = EditorInstance(file: tabFile)
94+
editor.setSelectedTab(tabFile)
9595
editor.clearFuture()
9696
editor.addToHistory(tabItem)
9797
}
@@ -100,22 +100,22 @@ struct EditorTabView: View {
100100
/// Close the current tab.
101101
func closeAction() {
102102
isAppeared = false
103-
editor.closeTab(file: item)
103+
editor.closeTab(file: tabFile)
104104
}
105105

106106
init(
107-
item: CEWorkspaceFile,
107+
file: CEWorkspaceFile,
108108
index: Int,
109109
draggingTabId: CEWorkspaceFile.ID?,
110110
onDragTabId: CEWorkspaceFile.ID?,
111111
closeButtonGestureActive: Binding<Bool>
112112
) {
113-
self.item = item
113+
self.tabFile = file
114114
self.index = index
115115
self.draggingTabId = draggingTabId
116116
self.onDragTabId = onDragTabId
117117
self._closeButtonGestureActive = closeButtonGestureActive
118-
self._fileObserver = StateObject(wrappedValue: EditorTabFileObserver(item: item))
118+
self._fileObserver = StateObject(wrappedValue: EditorTabFileObserver(file: file))
119119
}
120120

121121
@ViewBuilder var content: some View {
@@ -126,15 +126,15 @@ struct EditorTabView: View {
126126
)
127127
// Tab content (icon and text).
128128
HStack(alignment: .center, spacing: 3) {
129-
Image(nsImage: item.nsIcon)
129+
Image(nsImage: tabFile.nsIcon)
130130
.frame(width: 16, height: 16)
131131
.foregroundColor(
132132
fileIconStyle == .color
133133
&& activeState != .inactive && isActiveEditor
134-
? item.iconColor
134+
? tabFile.iconColor
135135
: .secondary
136136
)
137-
Text(item.name)
137+
Text(tabFile.name)
138138
.font(
139139
isTemporary
140140
? .system(size: 11.0).italic()
@@ -146,7 +146,7 @@ struct EditorTabView: View {
146146
.frame(maxHeight: .infinity) // To max-out the parent (tab bar) area.
147147
.accessibilityElement(children: .ignore)
148148
.accessibilityAddTraits(.isStaticText)
149-
.accessibilityLabel(item.name)
149+
.accessibilityLabel(tabFile.name)
150150
.padding(.horizontal, 20)
151151
.overlay {
152152
ZStack {
@@ -157,7 +157,7 @@ struct EditorTabView: View {
157157
isDragging: draggingTabId != nil || onDragTabId != nil,
158158
closeAction: closeAction,
159159
closeButtonGestureActive: $closeButtonGestureActive,
160-
item: item,
160+
item: tabFile,
161161
isHoveringClose: $isHoveringClose
162162
)
163163
}
@@ -234,8 +234,8 @@ struct EditorTabView: View {
234234
// This padding is to avoid background color overlapping with top divider.
235235
.padding(.top, 1)
236236
.zIndex(isActive ? 2 : (isDragging ? 3 : (isPressing ? 1 : 0)))
237-
.id(item.id)
238-
.tabBarContextMenu(item: item, isTemporary: isTemporary)
237+
.id(tabFile.id)
238+
.tabBarContextMenu(item: tabFile, isTemporary: isTemporary)
239239
.accessibilityElement(children: .contain)
240240
.onAppear {
241241
workspace.workspaceFileManager?.addObserver(fileObserver)

CodeEdit/Features/Editor/TabBar/Tabs/Tab/Models/EditorTabFileObserver.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ import SwiftUI
1212
final class EditorTabFileObserver: ObservableObject, CEWorkspaceFileManagerObserver {
1313
@Published private(set) var isDeleted = false
1414

15-
private let item: CEWorkspaceFile
15+
private let tabFile: CEWorkspaceFile
1616

17-
init(item: CEWorkspaceFile) {
18-
self.item = item
17+
init(file: CEWorkspaceFile) {
18+
self.tabFile = file
1919
}
2020

2121
func fileManagerUpdated(updatedItems: Set<CEWorkspaceFile>) {
22-
guard let parent = item.parent else {
23-
return
24-
}
25-
26-
if updatedItems.contains(parent) {
27-
isDeleted = item.doesExist == false
22+
if let parent = tabFile.parent, updatedItems.contains(parent) {
23+
isDeleted = tabFile.doesExist == false
2824
}
2925
}
3026
}

CodeEdit/Features/Editor/TabBar/Tabs/Views/EditorTabs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ struct EditorTabs: View {
261261
ForEach(Array(openedTabs.enumerated()), id: \.element) { index, id in
262262
if let item = editor.tabs.first(where: { $0.file.id == id }) {
263263
EditorTabView(
264-
item: item.file,
264+
file: item.file,
265265
index: index,
266266
draggingTabId: draggingTabId,
267267
onDragTabId: onDragTabId,

0 commit comments

Comments
 (0)