Skip to content

Commit 566e0a1

Browse files
Invalidate cached colour-value display on colorSpace change
The values cache backing EditableColorValue's fields was only keyed by format/style, so switching the display colour space in Preferences left every swatch showing stale numbers until an unrelated resync (a new pick, edit, or format/style toggle).
1 parent 05b1f8a commit 566e0a1

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

Pika/Views/EditableColorValue.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ struct EditableColorValue: View {
4949
private let baseSize: CGFloat = 18
5050
private let minSize: CGFloat = 11
5151

52-
/// Identifies which (format, style) a cached `values` array was decomposed for, so a
53-
/// format/style switch is detected even when the component count doesn't change (every
54-
/// non-hex format always has exactly 3 components).
52+
/// Identifies which (format, style, colorSpace) a cached `values` array was decomposed for,
53+
/// so a format/style switch — or a display colour-space switch in Preferences, which changes
54+
/// `decompose`'s output just as much — is detected even when the component count doesn't
55+
/// change (every non-hex format always has exactly 3 components).
5556
private struct FormatStyleKey: Equatable {
5657
let format: ColorFormat
5758
let style: CopyFormat
59+
let colorSpace: NSColorSpace
5860
}
5961

6062
@State private var width: CGFloat = 0
@@ -150,6 +152,7 @@ struct EditableColorValue: View {
150152
}
151153
.onChange(of: format) { _ in handleFormatOrStyleChange() }
152154
.onChange(of: style) { _ in handleFormatOrStyleChange() }
155+
.onChange(of: colorSpace) { _ in handleFormatOrStyleChange() }
153156
.onChange(of: dismissEditingTrigger) { _ in focusedIndex = nil }
154157
}
155158

@@ -165,11 +168,11 @@ struct EditableColorValue: View {
165168

166169
private func syncValuesFromColor(_ layout: DecomposedColor) {
167170
values = layout.values
168-
valuesKey = FormatStyleKey(format: format, style: style)
171+
valuesKey = FormatStyleKey(format: format, style: style, colorSpace: colorSpace)
169172
}
170173

171174
private func binding(for index: Int, layout: DecomposedColor) -> Binding<String> {
172-
let currentKey = FormatStyleKey(format: format, style: style)
175+
let currentKey = FormatStyleKey(format: format, style: style, colorSpace: colorSpace)
173176
return Binding(
174177
get: {
175178
guard valuesKey == currentKey, index < values.count else { return layout.values[index] }
@@ -189,9 +192,10 @@ struct EditableColorValue: View {
189192

190193
// MARK: - Editing lifecycle
191194

192-
/// A format or copy-style switch changes how the same colour is *displayed*, not the colour
193-
/// itself. Mid-edit, the typed values are in the old format's units and can't be reinterpreted
194-
/// safely, so abort the session rather than risk a bogus commit; otherwise just resync.
195+
/// A format, copy-style, or display colour-space switch changes how the same colour is
196+
/// *displayed*, not the colour itself. Mid-edit, the typed values are in the old units and
197+
/// can't be reinterpreted safely, so abort the session rather than risk a bogus commit;
198+
/// otherwise just resync.
195199
private func handleFormatOrStyleChange() {
196200
if isEditing {
197201
abortEditingForExternalPick()
@@ -263,7 +267,7 @@ struct EditableColorValue: View {
263267
isEditing = true
264268
preEditColor = eyedropper.color
265269
values = layout.values
266-
valuesKey = FormatStyleKey(format: format, style: style)
270+
valuesKey = FormatStyleKey(format: format, style: style, colorSpace: colorSpace)
267271
}
268272

269273
/// Recompose the working values and preview them live; flag invalid input for the pill.

0 commit comments

Comments
 (0)