Skip to content

Commit a987a4b

Browse files
committed
Code review
1 parent 60b5119 commit a987a4b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

frontend/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<body>
2121
<noscript>JavaScript is required</noscript>
2222
<!-- tabindex is used to allow the app to have focus while inside of it -->
23-
<div id="app" tabindex="0"></div>
23+
<div data-app id="app" tabindex="0"></div>
2424
</body>
2525

2626
</html>

frontend/src/io-managers/input.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ type EventListenerTarget = {
1111
};
1212

1313
export function createInputManager(editor: Editor, container: HTMLElement, dialog: DialogState, document: PortfolioState, fullscreen: FullscreenState): () => void {
14+
const app = window.document.querySelector("[data-app]") as HTMLElement | undefined;
15+
app?.focus();
16+
console.info(app);
17+
1418
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1519
const listeners: { target: EventListenerTarget; eventName: EventName; action: (event: any) => void; options?: boolean | AddEventListenerOptions }[] = [
1620
{ target: window, eventName: "resize", action: (): void => onWindowResize(container) },
@@ -27,17 +31,20 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
2731
{ target: window, eventName: "wheel", action: (e: WheelEvent): void => onMouseScroll(e), options: { passive: false } },
2832
{ target: window, eventName: "modifyinputfield", action: (e: CustomEvent): void => onModifyInputField(e) },
2933
{ target: window.document.body, eventName: "paste", action: (e: ClipboardEvent): void => onPaste(e) },
34+
{
35+
target: app as EventListenerTarget,
36+
eventName: "blur",
37+
action: (): void => blurApp(),
38+
},
3039
];
3140

3241
let viewportPointerInteractionOngoing = false;
3342
let textInput = undefined as undefined | HTMLDivElement;
3443
let inCanvas = true;
3544

36-
const app = window.document.getElementById("app");
37-
app?.focus();
38-
app?.addEventListener("blur", () => {
45+
function blurApp(): void {
3946
inCanvas = false;
40-
});
47+
}
4148

4249
// Keyboard events
4350

@@ -120,8 +127,11 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
120127
if (!viewportPointerInteractionOngoing && inFloatingMenu) return;
121128

122129
const { target } = e;
123-
inCanvas = (target instanceof Element && target.closest("[data-canvas]")) instanceof Element && !targetIsTextField(window.document.activeElement);
124-
if (inCanvas) app?.focus();
130+
const newInCanvas = (target instanceof Element && target.closest("[data-canvas]")) instanceof Element && !targetIsTextField(window.document.activeElement);
131+
if (newInCanvas && !inCanvas) {
132+
inCanvas = true;
133+
app?.focus();
134+
}
125135

126136
const modifiers = makeKeyboardModifiersBitfield(e);
127137
editor.instance.on_mouse_move(e.clientX, e.clientY, e.buttons, modifiers);

0 commit comments

Comments
 (0)