Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/src/components/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@
user-select: none;
}

body.hide-cursor * {
// Workaround to hide the cursor when dragging a number input in Safari, which doesn't work on its own during pointer lock
cursor: none !important;
}

// Needed for the viewport hole punch on desktop
html:has(body > .viewport-hole-punch),
body:has(> .viewport-hole-punch) {
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/components/widgets/inputs/NumberInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { PRESS_REPEAT_DELAY_MS, PRESS_REPEAT_INTERVAL_MS } from "@graphite/io-managers/input";
import { type NumberInputMode, type NumberInputIncrementBehavior } from "@graphite/messages";
import { browserVersion } from "@graphite/utility-functions/platform";
import { evaluateMathExpression } from "@graphite-frontend/wasm/pkg/graphite_wasm.js";

import { preventEscapeClosingParentFloatingMenu } from "@graphite/components/layout/FloatingMenu.svelte";
Expand Down Expand Up @@ -347,6 +348,10 @@

// Enter dragging state
target.requestPointerLock();

// Workaround for a Safari bug where it fails to hide the cursor during pointer lock.
if (browserVersion().toLowerCase().includes("safari")) document.body.classList.add("hide-cursor");

initialValueBeforeDragging = value;
cumulativeDragDelta = 0;

Expand All @@ -360,16 +365,14 @@

const pointerUp = () => {
// Confirm on release by setting the reset value to the current value, so once the pointer lock ends,
// the value is set to itself instead of the initial (abort) value in the "pointerlockchange" event handler function.
// the value is set to itself instead of the initial (abort) value in the `pointerlockchange` event handler function.
initialValueBeforeDragging = value;
cumulativeDragDelta = 0;

document.exitPointerLock();

// Fallback for Safari in case pointerlockchange never fires
setTimeout(() => {
if (!document.pointerLockElement) pointerLockChange();
}, 0);
// Fallback for Safari in case `pointerlockchange` never fires, so we don't get stuck dragging.
setTimeout(pointerLockChange, 0);
};
const pointerMove = (e: PointerEvent) => {
// Abort the drag if right click is down. This works here because a "pointermove" event is fired when right clicking even if the cursor didn't move.
Expand Down Expand Up @@ -407,6 +410,9 @@
// Do nothing if we just entered, rather than exited, pointer lock.
if (document.pointerLockElement) return;

// Workaround for a Safari bug where it fails to hide the cursor during pointer lock.
if (browserVersion().toLowerCase().includes("safari")) document.body.classList.remove("hide-cursor");

// Reset the value to the initial value if the drag was aborted, or to the current value if it was just confirmed by changing the initial value to the current value.
updateValue(initialValueBeforeDragging);
initialValueBeforeDragging = undefined;
Expand Down