From 8b9039f152685712bd8d6f384dec5239880a26bc Mon Sep 17 00:00:00 2001 From: Adam Argyle Date: Thu, 26 Nov 2026 03:45:40 -0800 Subject: [PATCH 1/2] Blur an emptied color stop input to delete the stop (#81) Emptying a stop's color text and leaving the field removes that stop (with one neighboring transition hint). The only color stop gets its previous color back. A window/tab switch doesn't count as leaving. The Remove menu action now shares removeStopAt(), which takes the hint before the last stop instead of leaving a dangling trailing hint. Co-Authored-By: Claude Opus 5.5 --- src/components/GradientStops.svelte | 32 +++++++++++++++++++++---- src/utils/removeStop.test.ts | 36 +++++++++++++++++++++++++++++ src/utils/stops.ts | 15 ++++++++++++ 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/utils/removeStop.test.ts diff --git a/src/components/GradientStops.svelte b/src/components/GradientStops.svelte index ad3fb38..35526a9 100644 --- a/src/components/GradientStops.svelte +++ b/src/components/GradientStops.svelte @@ -11,6 +11,7 @@ import {copyToClipboard} from '../utils/clipboard' import {randomNumber} from '../utils/numbers' + import {removeStopAt} from '../utils/stops' import {whatsTheGamutDamnit} from '../utils/colorspace' import RangeSlider from './RangeSlider.svelte' @@ -39,10 +40,7 @@ const target = event.target as HTMLSelectElement switch (target.value) { case 'Remove': - if (colorStopCount() <= 1) break - const newStops = [...$gradient_stops] - newStops.splice(position, 2) - $gradient_stops = newStops + $gradient_stops = removeStopAt($gradient_stops, position) break case 'Reset': const resetStops = [...$gradient_stops] @@ -135,6 +133,30 @@ $active_stop_index = null } + // Emptying a stop's color text and leaving the field deletes that stop (#81). + // The only color stop can't be deleted, so it gets the color it had on focus back. + let colorOnFocus = '' + + function rememberColor(stop: GradientStop) { + colorOnFocus = stop.color + } + + function removeIfColorEmptied(stop: GradientStop) { + if (String(stop.color ?? '').trim() !== '') return + // switching windows/tabs blurs the field too; wait for a real blur when the user comes back + if (!document.hasFocus()) return + const index = $gradient_stops.indexOf(stop) + if (index < 0) return + + if (colorStopCount() > 1) { + $gradient_stops = removeStopAt($gradient_stops, index) + } + else { + stop.color = colorOnFocus + $gradient_stops = [...$gradient_stops] + } + } + function fixIfEmptied(stop: GradientStop) { if (stop.percentage === null || stop.percentage === undefined) { stop.percentage = String(stop.auto || '') @@ -299,7 +321,7 @@ {/if}
- + rememberColor(stop)} onblur={() => removeIfColorEmptied(stop)}/>