Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(ui): scrub relative to the current value

Josh Corbett77f1d2d6fbb6
diff --git a/invokeai/frontend/webv2/src/platform/ui/ScrubberField.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/ScrubberField.browser.test.tsx
index 21240db003..27af0f45f8 100644
--- a/invokeai/frontend/webv2/src/platform/ui/ScrubberField.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/ScrubberField.browser.test.tsx
@@ -86,17 +86,18 @@ describe('ScrubberField', () => {
expect(valueButton()?.getAttribute('aria-label')).toBe('Edit Steps');
});
- it('jumps to the pressed position, then follows the drag snapped to the step', async () => {
+ it('scrubs relative to the current value from wherever the press lands, snapped to the step', async () => {
const { frame, onChange } = await mount({ step: 5 });
+ // Like a native iOS slider: pressing away from the thumb does not move it there.
await pointer(frame, 'pointerdown', { clientX: trackX(frame, 0.5) });
- expect(onChange).toHaveBeenLastCalledWith(50);
+ expect(onChange).not.toHaveBeenCalled();
expect(frame.hasAttribute('data-dragging')).toBe(true);
await pointer(window, 'pointermove', { clientX: trackX(frame, 0.73) });
- expect(onChange).toHaveBeenLastCalledWith(75);
+ expect(onChange).toHaveBeenLastCalledWith(55);
await pointer(window, 'pointermove', { clientX: trackX(frame, 2) });
@@ -111,6 +112,23 @@ describe('ScrubberField', () => {
expect(onChange).toHaveBeenLastCalledWith(100);
});
+ it('reaches either bound from a press on the far side of the thumb', async () => {
+ const { frame, onChange } = await mount();
+
+ // Right of the thumb: the value is not capped by where the press landed.
+ await pointer(frame, 'pointerdown', { clientX: trackX(frame, 0.9) });
+ await pointer(window, 'pointermove', { clientX: trackX(frame, 1.7) });
+
+ expect(onChange).toHaveBeenLastCalledWith(100);
+ await pointer(window, 'pointerup', { clientX: trackX(frame, 1.7) });
+
+ await pointer(frame, 'pointerdown', { clientX: trackX(frame, 0.1) });
+ await pointer(window, 'pointermove', { clientX: trackX(frame, -0.5) });
+
+ expect(onChange).toHaveBeenLastCalledWith(0);
+ await pointer(window, 'pointerup', { clientX: trackX(frame, -0.5) });
+ });
+
it('scrubs relative to the current value at a tenth of the sensitivity while Shift is held', async () => {
const { frame, onChange } = await mount();
@@ -128,7 +146,8 @@ describe('ScrubberField', () => {
it('snaps to the nearest stop while Alt is held', async () => {
const { frame, onChange } = await mount({ marks: [0, 20, 50, 100] });
- await pointer(frame, 'pointerdown', { altKey: true, clientX: trackX(frame, 0.62) });
+ await pointer(frame, 'pointerdown', { altKey: true, clientX: trackX(frame, 0.3) });
+ await pointer(window, 'pointermove', { altKey: true, clientX: trackX(frame, 0.45) });
expect(onChange).toHaveBeenLastCalledWith(50);
@@ -143,7 +162,8 @@ describe('ScrubberField', () => {
// gesture would otherwise snap straight off the track's end.
const { frame, onChange } = await mount({ defaultValue: 30, marks: [50], max: 10, value: 5 });
- await pointer(frame, 'pointerdown', { altKey: true, clientX: trackX(frame, 0.9) });
+ await pointer(frame, 'pointerdown', { altKey: true, clientX: trackX(frame, 0.5) });
+ await pointer(window, 'pointermove', { altKey: true, clientX: trackX(frame, 0.9) });
expect(onChange).toHaveBeenLastCalledWith(9);
await pointer(window, 'pointerup', { clientX: trackX(frame, 0.9) });
@@ -287,19 +307,16 @@ describe('ScrubberField', () => {
const { frame, onChange } = await mount();
await pointer(frame, 'pointerdown', { clientX: trackX(frame, 0.5), pointerId: 1 });
-
- expect(onChange).toHaveBeenLastCalledWith(50);
-
await pointer(window, 'pointermove', { clientX: trackX(frame, 0.8), pointerId: 2 });
await pointer(window, 'pointerup', { clientX: trackX(frame, 0.8), pointerId: 2 });
- expect(onChange).toHaveBeenLastCalledWith(50);
+ expect(onChange).not.toHaveBeenCalled();
expect(frame.hasAttribute('data-dragging')).toBe(true);
await pointer(window, 'pointermove', { clientX: trackX(frame, 0.6), pointerId: 1 });
await pointer(window, 'pointerup', { clientX: trackX(frame, 0.6), pointerId: 1 });
- expect(onChange).toHaveBeenLastCalledWith(60);
+ expect(onChange).toHaveBeenLastCalledWith(40);
expect(frame.hasAttribute('data-dragging')).toBe(false);
});
@@ -389,19 +406,20 @@ describe('ScrubberField', () => {
const { frame, onChange } = await mount();
await pointer(frame, 'pointerdown', { clientX: trackX(frame, 0.5) });
+ await pointer(window, 'pointermove', { clientX: trackX(frame, 0.6) });
- expect(onChange).toHaveBeenLastCalledWith(50);
+ expect(onChange).toHaveBeenLastCalledWith(40);
- await pointer(window, 'pointermove', { clientX: trackX(frame, 0.5), shiftKey: true });
await pointer(window, 'pointermove', { clientX: trackX(frame, 0.6), shiftKey: true });
+ await pointer(window, 'pointermove', { clientX: trackX(frame, 0.7), shiftKey: true });
- expect(onChange).toHaveBeenLastCalledWith(51);
+ expect(onChange).toHaveBeenLastCalledWith(41);
// Releasing Shift re-anchors at full sensitivity rather than jumping to the pointer.
- await pointer(window, 'pointermove', { clientX: trackX(frame, 0.6) });
await pointer(window, 'pointermove', { clientX: trackX(frame, 0.7) });
+ await pointer(window, 'pointermove', { clientX: trackX(frame, 0.8) });
- expect(onChange).toHaveBeenLastCalledWith(61);
+ expect(onChange).toHaveBeenLastCalledWith(51);
await pointer(window, 'pointercancel', {});
expect(frame.hasAttribute('data-dragging')).toBe(false);
@@ -417,7 +435,7 @@ describe('ScrubberField', () => {
await pointer(window, 'pointermove', { clientX: trackX(frame, 0.7), pointerType: 'touch' });
- expect(onChange).toHaveBeenLastCalledWith(70);
+ expect(onChange).toHaveBeenLastCalledWith(50);
await pointer(window, 'pointerup', { pointerType: 'touch' });
});
diff --git a/invokeai/frontend/webv2/src/platform/ui/ScrubberField.tsx b/invokeai/frontend/webv2/src/platform/ui/ScrubberField.tsx
index bd61663afe..36284d41a9 100644
--- a/invokeai/frontend/webv2/src/platform/ui/ScrubberField.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/ScrubberField.tsx
@@ -191,8 +191,9 @@ const isSameExtents = (a: TextExtents | null, b: TextExtents): boolean =>
/**
* One-row numeric parameter: label left, value right, the whole frame is the
- * track. Pointer down anywhere but the value scrubs (Shift: fine, Alt: stops
- * only); the value is a button that swaps in a text editor; arrows step
+ * track. Dragging anywhere but the value scrubs relative to the current value
+ * — a press alone never moves it (Shift: fine, Alt: stops only); the value is
+ * a button that swaps in a text editor; arrows step
* (Shift/PageUp/PageDown: ×10, Home/End: bounds); double-click or
* Backspace/Delete restores `defaultValue`. Owns its label, hint, and help or
* error line, so it replaces a `Field` + slider pairing outright. Debouncing
@@ -356,15 +357,15 @@ export const ScrubberField = ({
const rect = root.getBoundingClientRect();
const trackLeft = rect.left + TRACK_INSET_PX;
const trackWidth = Math.max(1, rect.width - TRACK_INSET_PX * 2);
- const valueAt = (clientX: number): number => min + clamp((clientX - trackLeft) / trackWidth, 0, 1) * range;
+ // Unclamped, so a press left of the thumb can still be dragged past the track's end to max.
+ const valueAt = (clientX: number): number => min + ((clientX - trackLeft) / trackWidth) * range;
const session = new AbortController();
let latest = value;
let isPendingTouch = event.pointerType === 'touch';
- // Once Shift enters a gesture it stays relative (re-anchored on each ratio
- // change), so neither pressing nor releasing Shift mid-drag jumps.
- let anchor: { clientX: number; ratio: number; value: number } | null = event.shiftKey
- ? { clientX: event.clientX, ratio: FINE_DRAG_RATIO, value }
- : null;
+ // A gesture is relative to the value it started from, wherever the press
+ // lands (like a native iOS slider): re-anchoring on each ratio change means
+ // neither pressing nor releasing Shift mid-drag jumps.
+ let anchor = { clientX: event.clientX, ratio: event.shiftKey ? FINE_DRAG_RATIO : 1, value };
pointerSessionRef.current = session;
setIsDragging(true);
@@ -380,20 +381,14 @@ export const ScrubberField = ({
type PointerSample = { altKey: boolean; clientX: number; pointerId: number; shiftKey: boolean };
const resolve = (pointer: PointerSample): number => {
- let raw: number;
+ const ratio = pointer.shiftKey ? FINE_DRAG_RATIO : 1;
- if (pointer.shiftKey || anchor) {
- const ratio = pointer.shiftKey ? FINE_DRAG_RATIO : 1;
-
- if (anchor?.ratio !== ratio) {
- anchor = { clientX: pointer.clientX, ratio, value: latest };
- }
-
- raw = anchor.value + (valueAt(pointer.clientX) - valueAt(anchor.clientX)) * ratio;
- } else {
- raw = valueAt(pointer.clientX);
+ if (anchor.ratio !== ratio) {
+ anchor = { clientX: pointer.clientX, ratio, value: latest };
}
+ const raw = anchor.value + (valueAt(pointer.clientX) - valueAt(anchor.clientX)) * ratio;
+
return pointer.altKey && markValues?.length ? nearestMark(raw, markValues) : snapToStep(raw);
};
// The gesture belongs to the pointer that started it; a second finger or
@@ -428,11 +423,6 @@ export const ScrubberField = ({
setIsDragging(false);
};
- // A fine gesture starts from the current value, never from the press position.
- if (!event.shiftKey) {
- apply(event);
- }
-
window.addEventListener('pointermove', apply, { signal: session.signal });
window.addEventListener('pointerup', end, { signal: session.signal });
window.addEventListener('pointercancel', end, { signal: session.signal });