@@ -11,6 +11,10 @@ type EventListenerTarget = {
11
11
} ;
12
12
13
13
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
+
14
18
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15
19
const listeners : { target : EventListenerTarget ; eventName : EventName ; action : ( event : any ) => void ; options ?: boolean | AddEventListenerOptions } [ ] = [
16
20
{ target : window , eventName : "resize" , action : ( ) : void => onWindowResize ( container ) } ,
@@ -27,17 +31,20 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
27
31
{ target : window , eventName : "wheel" , action : ( e : WheelEvent ) : void => onMouseScroll ( e ) , options : { passive : false } } ,
28
32
{ target : window , eventName : "modifyinputfield" , action : ( e : CustomEvent ) : void => onModifyInputField ( e ) } ,
29
33
{ 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
+ } ,
30
39
] ;
31
40
32
41
let viewportPointerInteractionOngoing = false ;
33
42
let textInput = undefined as undefined | HTMLDivElement ;
34
43
let inCanvas = true ;
35
44
36
- const app = window . document . getElementById ( "app" ) ;
37
- app ?. focus ( ) ;
38
- app ?. addEventListener ( "blur" , ( ) => {
45
+ function blurApp ( ) : void {
39
46
inCanvas = false ;
40
- } ) ;
47
+ }
41
48
42
49
// Keyboard events
43
50
@@ -120,8 +127,11 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
120
127
if ( ! viewportPointerInteractionOngoing && inFloatingMenu ) return ;
121
128
122
129
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
+ }
125
135
126
136
const modifiers = makeKeyboardModifiersBitfield ( e ) ;
127
137
editor . instance . on_mouse_move ( e . clientX , e . clientY , e . buttons , modifiers ) ;
0 commit comments