Skip to content

Fix number slider value getting stuck tied to mouse position - #4514

Open
Akansh475 wants to merge 1 commit into
GraphiteEditor:masterfrom
Akansh475:fix-slider-drag-4231
Open

Fix number slider value getting stuck tied to mouse position#4514
Akansh475 wants to merge 1 commit into
GraphiteEditor:masterfrom
Akansh475:fix-slider-drag-4231

Conversation

@Akansh475

Copy link
Copy Markdown

Fixes #4231

I dug into this and found the root cause: document.exitPointerLock() is
async, and the matching pointerlockchange event can fire quite late in
some cases. If you release a drag and then quickly start a new one before
that event fires, the old drag's handler was still writing to shared
variables (initialValueBeforeDragging, cumulativeDragDelta,
activeDragCleanup). That's what caused the jump — the stale handler would
overwrite the new drag's in-progress value, and in some cases even tear
down the new drag's listeners entirely by clearing the shared cleanup
reference.

The fix moves this state into closures scoped to each individual drag
session, so a late-firing event from an old session can only ever touch
its own data and never interfere with whatever drag is currently active.

Tested by reproducing both scenarios from the issue:

  • rapid click-dragging the slider back and forth in short bursts
  • losing window focus mid-drag (e.g. clicking into devtools) and then
    clicking back

Neither causes the jump/stuck behavior anymore after this change.

Probably related to #2807 as well, since that's the same drag code path.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Confidence score: 3/5

  • frontend/src/components/widgets/inputs/NumberInput.svelte can let an older pointer-lock completion clear a newer session’s shared abort baseline, potentially producing incorrect number-input delta/abort behavior; make the cleanup conditional on the owning session and clear the shared baseline and delta only when appropriate.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="frontend/src/components/widgets/inputs/NumberInput.svelte">

<violation number="1" location="frontend/src/components/widgets/inputs/NumberInput.svelte:572">
P2: After `localInitialValue` is cleared, this condition is tautologically true, so every pointer-lock completion clears the shared abort baseline, including a newer session's baseline. Clear the shared baseline and delta only when this callback still owns the active drag session.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment on lines +572 to 575
if (initialValueBeforeDragging === localInitialValue || initialValueBeforeDragging !== undefined) {
initialValueBeforeDragging = undefined;
}
cumulativeDragDelta = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: After localInitialValue is cleared, this condition is tautologically true, so every pointer-lock completion clears the shared abort baseline, including a newer session's baseline. Clear the shared baseline and delta only when this callback still owns the active drag session.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/src/components/widgets/inputs/NumberInput.svelte, line 572:

<comment>After `localInitialValue` is cleared, this condition is tautologically true, so every pointer-lock completion clears the shared abort baseline, including a newer session's baseline. Clear the shared baseline and delta only when this callback still owns the active drag session.</comment>

<file context>
@@ -491,12 +566,17 @@
+			updateValue(localInitialValue);
+			localInitialValue = undefined;
+			localCumulativeDragDelta = 0;
+			if (initialValueBeforeDragging === localInitialValue || initialValueBeforeDragging !== undefined) {
+				initialValueBeforeDragging = undefined;
+			}
</file context>
Suggested change
if (initialValueBeforeDragging === localInitialValue || initialValueBeforeDragging !== undefined) {
initialValueBeforeDragging = undefined;
}
cumulativeDragDelta = 0;
if (activeDragCleanup === dragCleanup) {
initialValueBeforeDragging = undefined;
cumulativeDragDelta = 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Values in property sliders getting tied to mouse position

1 participant