@@ -21,13 +21,9 @@ export function createInputManager(editor: Editor, dialog: DialogState, document
21
21
app ?. focus ( ) ;
22
22
23
23
let viewportPointerInteractionOngoing = false ;
24
- let textInput = undefined as undefined | HTMLDivElement ;
24
+ let textToolInteractiveInputElement = undefined as undefined | HTMLDivElement ;
25
25
let canvasFocused = true ;
26
26
27
- function blurApp ( ) : void {
28
- canvasFocused = false ;
29
- }
30
-
31
27
// Event listeners
32
28
33
29
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -43,7 +39,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, document
43
39
{ target : window , eventName : "wheel" , action : ( e : WheelEvent ) => onWheelScroll ( e ) , options : { passive : false } } ,
44
40
{ target : window , eventName : "modifyinputfield" , action : ( e : CustomEvent ) => onModifyInputField ( e ) } ,
45
41
{ target : window , eventName : "focusout" , action : ( ) => ( canvasFocused = false ) } ,
46
- { target : window . document , eventName : "contextmenu" , action : ( e : MouseEvent ) => e . preventDefault ( ) } ,
42
+ { target : window . document , eventName : "contextmenu" , action : ( e : MouseEvent ) => onContextMenu ( e ) } ,
47
43
{ target : window . document , eventName : "fullscreenchange" , action : ( ) => fullscreen . fullscreenModeChanged ( ) } ,
48
44
{ target : window . document . body , eventName : "paste" , action : ( e : ClipboardEvent ) => onPaste ( e ) } ,
49
45
] ;
@@ -154,7 +150,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, document
154
150
const { target } = e ;
155
151
const isTargetingCanvas = target instanceof Element && target . closest ( "[data-canvas]" ) ;
156
152
const inDialog = target instanceof Element && target . closest ( "[data-dialog-modal] [data-floating-menu-content]" ) ;
157
- const inTextInput = target === textInput ;
153
+ const inTextInput = target === textToolInteractiveInputElement ;
158
154
159
155
if ( get ( dialog ) . visible && ! inDialog ) {
160
156
dialog . dismissDialog ( ) ;
@@ -163,7 +159,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, document
163
159
}
164
160
165
161
if ( ! inTextInput ) {
166
- if ( textInput ) editor . instance . onChangeText ( textInputCleanup ( textInput . innerText ) ) ;
162
+ if ( textToolInteractiveInputElement ) editor . instance . onChangeText ( textInputCleanup ( textToolInteractiveInputElement . innerText ) ) ;
167
163
else viewportPointerInteractionOngoing = isTargetingCanvas instanceof Element ;
168
164
}
169
165
@@ -179,7 +175,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, document
179
175
function onPointerUp ( e : PointerEvent ) : void {
180
176
if ( ! e . buttons ) viewportPointerInteractionOngoing = false ;
181
177
182
- if ( ! textInput ) {
178
+ if ( ! textToolInteractiveInputElement ) {
183
179
const modifiers = makeKeyboardModifiersBitfield ( e ) ;
184
180
editor . instance . onMouseUp ( e . clientX , e . clientY , e . buttons , modifiers ) ;
185
181
}
@@ -188,7 +184,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, document
188
184
function onDoubleClick ( e : PointerEvent ) : void {
189
185
if ( ! e . buttons ) viewportPointerInteractionOngoing = false ;
190
186
191
- if ( ! textInput ) {
187
+ if ( ! textToolInteractiveInputElement ) {
192
188
const modifiers = makeKeyboardModifiersBitfield ( e ) ;
193
189
editor . instance . onDoubleClick ( e . clientX , e . clientY , e . buttons , modifiers ) ;
194
190
}
@@ -215,8 +211,16 @@ export function createInputManager(editor: Editor, dialog: DialogState, document
215
211
}
216
212
}
217
213
214
+ function onContextMenu ( e : MouseEvent ) : void {
215
+ if ( ! targetIsTextField ( e . target || undefined ) && e . target !== textToolInteractiveInputElement ) {
216
+ e . preventDefault ( ) ;
217
+ }
218
+ }
219
+
220
+ // Receives a custom event dispatched when the user begins interactively editing with the text tool.
221
+ // We keep a copy of the text input element to check against when it's active for text entry.
218
222
function onModifyInputField ( e : CustomEvent ) : void {
219
- textInput = e . detail ;
223
+ textToolInteractiveInputElement = e . detail ;
220
224
}
221
225
222
226
// Window events
0 commit comments