Skip to content

Commit d9bd654

Browse files
Address review feedback: dedupe scrub-precision formula, fix stale comment
Extract initialScrubDecimalPlaces so click-drag and scroll-to-scrub compute the starting decimal precision from one place instead of two independently duplicated formulas. Also correct EyedropperButton's comment now that showsTypeLabels is hardcoded true and the fade it describes is vestigial.
1 parent 2cc1ec4 commit d9bd654

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

Pika/Views/EditableColorValue.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,7 @@ struct ColorComponentField: View {
671671
if scrollOrigin == nil {
672672
scrollOrigin = Double(text.trimmingCharacters(in: .whitespaces)) ?? 0
673673
scrollAccumulated = 0
674-
scrollDecimalPlaces = min(
675-
ScrubTextField.precisionRange.upperBound,
676-
max(
677-
Self.naturalDecimalPlaces(forRange: component.range),
678-
Self.stableDecimalPlaces(for: text)
679-
)
680-
)
674+
scrollDecimalPlaces = Self.initialScrubDecimalPlaces(forRange: component.range, text: text)
681675
onDragBegin()
682676
}
683677
guard let origin = scrollOrigin else { return }
@@ -746,4 +740,17 @@ struct ColorComponentField: View {
746740
let decimals = text.distance(from: text.index(after: dotIndex), to: text.endIndex)
747741
return max(2, min(4, decimals))
748742
}
743+
744+
/// Decimal places to start a scrub session at: whichever is finer, the precision this
745+
/// component's drag step can actually resolve (`naturalDecimalPlaces`) or the precision
746+
/// already on display (`stableDecimalPlaces`, so starting a scrub never truncates what's
747+
/// shown), capped at `ScrubTextField.precisionRange`'s ceiling. Shared by click-drag
748+
/// (`ScrubTextField.beginDrag`) and scroll-to-scrub (`handleScrollDelta`) so the two paths
749+
/// can't drift out of sync the way their digit-budget math already has once.
750+
static func initialScrubDecimalPlaces(forRange range: ClosedRange<Double>?, text: String) -> Int {
751+
min(
752+
ScrubTextField.precisionRange.upperBound,
753+
max(naturalDecimalPlaces(forRange: range), stableDecimalPlaces(for: text))
754+
)
755+
}
749756
}

Pika/Views/EyedropperButton.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ struct EyedropperButton: View {
127127
// clicks. The type label and colour name disable hit-testing so clicks fall
128128
// through to the pick button behind them.
129129
VStack(alignment: .leading, spacing: 2.0) {
130-
// Visibility is size-aware (`adaptive.showsTypeLabels` already folds in the
131-
// preview-pill overlap) so labels fade out as the window shrinks and return
132-
// when it grows again. The invalid pill overrides the fade so it's never hidden.
130+
// `adaptive.showsTypeLabels` is hardcoded `true` (ContentView.swift) as of
131+
// `81fe9f9`, so the fade below is currently vestigial — kept in case that's
132+
// revisited, rather than stripped along with the conditional that once drove it.
133+
// The invalid pill overrides the fade so it's never hidden.
133134
let showsTypeLabel = adaptive.showsTypeLabels
134135
HStack(alignment: .firstTextBaseline, spacing: 6.0) {
135136
Text(eyedropper.type.description)

Pika/Views/ScrubTextField.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,7 @@ final class ScrubTextField: NSTextField {
466466
private func beginDrag(at location: NSPoint) {
467467
dragAnchorValue = Double(stringValue.trimmingCharacters(in: .whitespaces)) ?? 0
468468
dragAnchorX = location.x
469-
// Whichever is finer: the precision this component's drag step can actually resolve, or
470-
// the precision already on display (so starting a scrub never truncates what's shown).
471-
dragDecimalPlaces = min(
472-
Self.precisionRange.upperBound,
473-
max(
474-
ColorComponentField.naturalDecimalPlaces(forRange: range),
475-
ColorComponentField.stableDecimalPlaces(for: stringValue)
476-
)
477-
)
469+
dragDecimalPlaces = ColorComponentField.initialScrubDecimalPlaces(forRange: range, text: stringValue)
478470
dragBaseDecimalPlaces = dragDecimalPlaces
479471
NSCursor.resizeLeftRight.set()
480472
onDragBegin?()

0 commit comments

Comments
 (0)