Skip to content

Commit 5ddf1b2

Browse files
committed
refactor: cleanup code quality issues from review
- SearchFieldView: resolve theme font size inside body for reactivity - HorizontalSplitView: refresh binding in updateNSView to prevent stale reference - HorizontalSplitView: add 0.5pt threshold to resize callback to reduce re-renders - HorizontalSplitView: remove redundant splitView.display() calls - ConnectionSwitcherPopover: extract moveSelection helper to avoid repeated allItems computation - ContentView: remove dead saveCurrentSessionState stub
1 parent 5ff4711 commit 5ddf1b2

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

TablePro/ContentView.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,6 @@ struct ContentView: View {
429429
}
430430
}
431431

432-
private func saveCurrentSessionState() {
433-
// State is automatically saved through bindings
434-
}
435-
436432
// MARK: - Persistence
437433

438434
private func deleteConnection(_ connection: DatabaseConnection) {

TablePro/Views/Components/HorizontalSplitView.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct HorizontalSplitView<Leading: View, Trailing: View>: NSViewRepresentable {
5151
func updateNSView(_ splitView: NSSplitView, context: Context) {
5252
context.coordinator.leadingHosting?.rootView = leading
5353
context.coordinator.trailingHosting?.rootView = trailing
54+
context.coordinator.trailingWidth = $trailingWidth
5455
context.coordinator.minWidth = minTrailingWidth
5556
context.coordinator.maxWidth = maxTrailingWidth
5657

@@ -65,13 +66,11 @@ struct HorizontalSplitView<Leading: View, Trailing: View>: NSViewRepresentable {
6566
}
6667
splitView.setPosition(splitView.bounds.width, ofDividerAt: 0)
6768
trailingView.isHidden = true
68-
splitView.display()
6969
} else {
7070
trailingView.isHidden = false
7171
let targetWidth = context.coordinator.savedDividerPosition ?? trailingWidth
7272
splitView.adjustSubviews()
7373
splitView.setPosition(splitView.bounds.width - targetWidth, ofDividerAt: 0)
74-
splitView.display()
7574
}
7675
}
7776
}
@@ -81,8 +80,8 @@ struct HorizontalSplitView<Leading: View, Trailing: View>: NSViewRepresentable {
8180
var trailingHosting: NSHostingView<Trailing>?
8281
var lastCollapsedState = false
8382
var savedDividerPosition: CGFloat?
84-
var minWidth: CGFloat = 200
85-
var maxWidth: CGFloat = 600
83+
var minWidth: CGFloat = 0
84+
var maxWidth: CGFloat = 0
8685
var trailingWidth: Binding<CGFloat>
8786

8887
init(trailingWidth: Binding<CGFloat>) {
@@ -137,9 +136,8 @@ struct HorizontalSplitView<Leading: View, Trailing: View>: NSViewRepresentable {
137136
trailingHosting?.isHidden != true
138137
else { return }
139138
let width = splitView.subviews[1].frame.width
140-
if width > 0 {
141-
trailingWidth.wrappedValue = width
142-
}
139+
guard width > 0, abs(width - trailingWidth.wrappedValue) > 0.5 else { return }
140+
trailingWidth.wrappedValue = width
143141
}
144142
}
145143
}

TablePro/Views/Components/SearchFieldView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import SwiftUI
88
struct SearchFieldView: View {
99
let placeholder: String
1010
@Binding var text: String
11-
var fontSize: CGFloat = ThemeEngine.shared.activeTheme.typography.body
11+
var fontSize: CGFloat?
1212

1313
var body: some View {
14+
let resolvedSize = fontSize ?? ThemeEngine.shared.activeTheme.typography.body
1415
HStack(spacing: 6) {
1516
Image(systemName: "magnifyingglass")
16-
.font(.system(size: fontSize))
17+
.font(.system(size: resolvedSize))
1718
.foregroundStyle(.tertiary)
1819

1920
TextField(placeholder, text: $text)
2021
.textFieldStyle(.plain)
21-
.font(.system(size: fontSize))
22+
.font(.system(size: resolvedSize))
2223

2324
if !text.isEmpty {
2425
Button { text = "" } label: {

TablePro/Views/Toolbar/ConnectionSwitcherPopover.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,18 @@ struct ConnectionSwitcherPopover: View {
168168
return .handled
169169
}
170170
.onKeyPress(.upArrow) {
171-
if selectedIndex > 0 { selectedIndex -= 1 }
172-
return .handled
171+
moveSelection(by: -1)
173172
}
174173
.onKeyPress(.downArrow) {
175-
if selectedIndex < allItems.count - 1 { selectedIndex += 1 }
176-
return .handled
174+
moveSelection(by: 1)
177175
}
178176
.onKeyPress(characters: .init(charactersIn: "j"), phases: [.down, .repeat]) { keyPress in
179177
guard keyPress.modifiers.contains(.control) else { return .ignored }
180-
if selectedIndex < allItems.count - 1 { selectedIndex += 1 }
181-
return .handled
178+
return moveSelection(by: 1)
182179
}
183180
.onKeyPress(characters: .init(charactersIn: "k"), phases: [.down, .repeat]) { keyPress in
184181
guard keyPress.modifiers.contains(.control) else { return .ignored }
185-
if selectedIndex > 0 { selectedIndex -= 1 }
186-
return .handled
182+
return moveSelection(by: -1)
187183
}
188184
}
189185

@@ -194,6 +190,13 @@ struct ConnectionSwitcherPopover: View {
194190
case saved(DatabaseConnection)
195191
}
196192

193+
private func moveSelection(by offset: Int) -> KeyPress.Result {
194+
let newIndex = selectedIndex + offset
195+
guard newIndex >= 0, newIndex < allItems.count else { return .handled }
196+
selectedIndex = newIndex
197+
return .handled
198+
}
199+
197200
// MARK: - Subviews
198201

199202
private func connectionRow(

0 commit comments

Comments
 (0)