(null);
const parsed = parseGradient(value) ?? buildDefaultGradientModel(fallbackColor);
const commit = (next: GradientModel) => onCommit(serializeGradient(next));
@@ -247,13 +248,31 @@ export function GradientField({
if (disabled) return;
const rect = previewRef.current?.getBoundingClientRect();
if (!rect || rect.width <= 0) return;
- addStop(((event.clientX - rect.left) / rect.width) * 100);
+ const position = ((event.clientX - rect.left) / rect.width) * 100;
+ const hitStopIndex = parsed.stops.findIndex(
+ (stop) => (Math.abs(stop.position - position) / 100) * rect.width <= 8,
+ );
+ if (hitStopIndex >= 0) {
+ setSelectedStopIndex(hitStopIndex);
+ return;
+ }
+ addStop(position);
}}
>
{parsed.stops.map((stop, index) => (
- {
+ event.stopPropagation();
+ setSelectedStopIndex(index);
+ }}
+ className={`absolute top-1/2 h-4 w-4 -translate-y-1/2 rounded-full border-2 border-white/90 shadow-[0_0_0_1px_rgba(0,0,0,0.35)] ${
+ selectedStopIndex === index ? "ring-2 ring-panel-accent" : ""
+ }`}
style={{
left: `calc(${stop.position}% - 8px)`,
backgroundColor: stop.color,
diff --git a/packages/studio/src/components/editor/propertyPanelPrimitives.tsx b/packages/studio/src/components/editor/propertyPanelPrimitives.tsx
index f2916c4668..a0e01672ca 100644
--- a/packages/studio/src/components/editor/propertyPanelPrimitives.tsx
+++ b/packages/studio/src/components/editor/propertyPanelPrimitives.tsx
@@ -17,11 +17,14 @@ function CommitField({
const valueRef = useRef(value);
const draftRef = useRef(draft);
const inputRef = useRef(null);
+ const focusedRef = useRef(false);
+ const dirtyRef = useRef(false);
valueRef.current = value;
draftRef.current = draft;
useEffect(() => {
+ if (focusedRef.current && dirtyRef.current) return;
setDraft(value);
}, [value]);
@@ -36,6 +39,7 @@ function CommitField({
if (!nextDraft) return;
e.preventDefault();
e.stopPropagation();
+ dirtyRef.current = true;
setDraft(nextDraft);
scheduleCommitRef.current(nextDraft);
};
@@ -70,11 +74,21 @@ function CommitField({
type="text"
value={draft}
disabled={disabled}
+ onFocus={() => {
+ focusedRef.current = true;
+ }}
onChange={(e) => {
+ dirtyRef.current = true;
setDraft(e.target.value);
if (liveCommit) scheduleCommit(e.target.value);
}}
- onBlur={() => commitDraft(draft)}
+ onBlur={() => {
+ const wasDirty = dirtyRef.current;
+ focusedRef.current = false;
+ dirtyRef.current = false;
+ if (wasDirty) commitDraft(draft);
+ else setDraft(valueRef.current);
+ }}
onKeyDown={(e) => {
if (e.key === "Enter") {
(e.target as HTMLInputElement).blur();
@@ -84,6 +98,7 @@ function CommitField({
const nextDraft = adjustNumericToken(draft, e.key === "ArrowUp" ? 1 : -1, e);
if (!nextDraft) return;
e.preventDefault();
+ dirtyRef.current = true;
setDraft(nextDraft);
scheduleCommit(nextDraft);
}}