Skip to content

Commit 200f879

Browse files
refactor wrap abort helper
1 parent 57a87a6 commit 200f879

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

frontend/src/components/panels/Document.svelte

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@
9090
editor.appWindowPointerLockMove(dx, dy);
9191
} catch (_) {}
9292
}
93+
function abortSoftwareCursorWrap() {
94+
softwareCursorVisible = false;
95+
updateMouseCursor("Default");
96+
try {
97+
editor.onKeyDown("Escape", 0, false);
98+
editor.onKeyUp("Escape", 0, false);
99+
} catch (_) {}
100+
}
93101
function handlePointerLockChange() {
94102
if (!softwareCursorVisible) return;
95103
if (isWeb && !window.document.pointerLockElement) {
96-
try {
97-
editor.onKeyDown("Escape", 0, false);
98-
editor.onKeyUp("Escape", 0, false);
99-
} catch (_) {}
104+
abortSoftwareCursorWrap();
100105
}
101106
}
102107
@@ -559,22 +564,10 @@
559564
try {
560565
const maybePromise = viewport.requestPointerLock?.() as unknown as Promise<void> | undefined;
561566
if (maybePromise && typeof (maybePromise as Promise<void>).catch === "function") {
562-
(maybePromise as Promise<void>).catch(() => {
563-
softwareCursorVisible = false;
564-
updateMouseCursor("Default");
565-
try {
566-
editor.onKeyDown("Escape", 0, false);
567-
editor.onKeyUp("Escape", 0, false);
568-
} catch (_) {}
569-
});
567+
(maybePromise as Promise<void>).catch(() => abortSoftwareCursorWrap());
570568
}
571569
} catch (_) {
572-
softwareCursorVisible = false;
573-
updateMouseCursor("Default");
574-
try {
575-
editor.onKeyDown("Escape", 0, false);
576-
editor.onKeyUp("Escape", 0, false);
577-
} catch (_) {}
570+
abortSoftwareCursorWrap();
578571
}
579572
} else if (!data.visible && window.document.pointerLockElement === viewport) {
580573
try {

0 commit comments

Comments
 (0)