Skip to content

Commit ac89fe7

Browse files
committed
fix: address review issues in theme engine migration
1 parent 98cfb16 commit ac89fe7

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

TablePro/Theme/HexColor.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ extension String {
77
let hex = trimmingCharacters(in: .whitespacesAndNewlines)
88
.trimmingCharacters(in: CharacterSet(charactersIn: "#"))
99

10-
guard hex.count == 6 || hex.count == 8 else {
10+
let hexLength = (hex as NSString).length
11+
guard hexLength == 6 || hexLength == 8 else {
1112
return .gray
1213
}
1314

@@ -18,7 +19,7 @@ extension String {
1819

1920
let r, g, b, a: CGFloat
2021

21-
if hex.count == 8 {
22+
if hexLength == 8 {
2223
r = CGFloat((value >> 24) & 0xFF) / 255.0
2324
g = CGFloat((value >> 16) & 0xFF) / 255.0
2425
b = CGFloat((value >> 8) & 0xFF) / 255.0

TablePro/Views/Results/DataGridCellFactory.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ final class DataGridCellFactory {
361361
/// Maximum characters to consider per cell for width estimation
362362
private static let maxMeasureChars = 50
363363
/// Font for measuring header
364-
private static let headerFont = NSFont.systemFont(ofSize: ThemeEngine.shared.activeTheme.typography.body, weight: .semibold)
364+
private var headerFont: NSFont {
365+
NSFont.systemFont(ofSize: ThemeEngine.shared.activeTheme.typography.body, weight: .semibold)
366+
}
365367

366368
/// Calculate column width based on header name only (used for initial display)
367369
func calculateColumnWidth(for columnName: String) -> CGFloat {
368-
let attributes: [NSAttributedString.Key: Any] = [.font: Self.headerFont]
370+
let attributes: [NSAttributedString.Key: Any] = [.font: headerFont]
369371
let size = (columnName as NSString).size(withAttributes: attributes)
370372
let width = size.width + 48 // padding for sort indicator + margins
371373
return min(max(width, Self.minColumnWidth), Self.maxColumnWidth)

TablePro/Views/Results/DataGridView.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,8 @@ final class TableViewCoordinator: NSObject, NSTableViewDelegate, NSTableViewData
776776
object: nil,
777777
queue: .main
778778
) { [weak self] _ in
779-
guard let self else { return }
780-
DispatchQueue.main.async { [weak self] in
781-
guard let self, let tableView = self.tableView else { return }
782-
Self.updateVisibleCellFonts(tableView: tableView)
783-
}
779+
guard let self, let tableView = self.tableView else { return }
780+
Self.updateVisibleCellFonts(tableView: tableView)
784781
}
785782
}
786783

TablePro/Views/Settings/Appearance/ThemeEditorFontsSection.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,18 @@ struct ThemeEditorFontsSection: View {
116116
}
117117

118118
private func updateFont(_ mutate: (inout ThemeFonts) -> Void) {
119-
var updated = editingTheme ?? theme
120-
mutate(&updated.fonts)
119+
let base = editingTheme ?? theme
121120

122-
if updated.isBuiltIn {
123-
var copy = engine.duplicateTheme(updated, newName: updated.name + " (Custom)")
121+
if base.isBuiltIn {
122+
var copy = engine.duplicateTheme(base, newName: base.name + " (Custom)")
124123
mutate(&copy.fonts)
125124
try? engine.saveUserTheme(copy)
126125
engine.activateTheme(copy)
127126
editingTheme = copy
128127
onThemeDuplicated?(copy)
129128
} else {
129+
var updated = base
130+
mutate(&updated.fonts)
130131
try? engine.saveUserTheme(updated)
131132
editingTheme = updated
132133
}

TablePro/Views/Settings/ThemePreviewCard.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,16 @@ struct ThemePreviewCard: View {
106106
.fill(theme.sidebar.background.swiftUIColor)
107107

108108
VStack(alignment: .leading, spacing: size == .compact ? 3 : 4) {
109+
let widths: [CGFloat] = size == .compact
110+
? [10, 14, 13, 9]
111+
: [14, 18, 17, 12]
109112
ForEach(0..<4, id: \.self) { i in
110113
RoundedRectangle(cornerRadius: 1)
111114
.fill(i == 1
112115
? theme.sidebar.selectedItem.swiftUIColor.opacity(0.6)
113116
: theme.sidebar.text.swiftUIColor.opacity(0.25))
114117
.frame(
115-
width: i == 1
116-
? (size == .compact ? 14 : 18)
117-
: CGFloat.random(in: size == .compact ? 8...16 : 12...20),
118+
width: widths[i],
118119
height: codeLineHeight
119120
)
120121
}

0 commit comments

Comments
 (0)