1
1
/* @flow strict */
2
2
3
- const compositionMap = new WeakMap ( )
4
-
5
3
export function install ( input : HTMLTextAreaElement | HTMLInputElement , list : HTMLElement ) : void {
6
4
input . addEventListener ( 'compositionstart' , trackComposition )
7
5
input . addEventListener ( 'compositionend' , trackComposition )
@@ -17,13 +15,14 @@ export function uninstall(input: HTMLTextAreaElement | HTMLInputElement, list: H
17
15
list . removeEventListener ( 'click' , commitWithElement )
18
16
}
19
17
18
+ let isComposing = false
20
19
const ctrlBindings = ! ! navigator . userAgent . match ( / M a c i n t o s h / )
21
20
22
21
function keyboardBindings ( event : KeyboardEvent ) {
23
22
if ( event . shiftKey || event . metaKey || event . altKey ) return
24
23
const input = event . currentTarget
25
24
if ( ! ( input instanceof HTMLTextAreaElement || input instanceof HTMLInputElement ) ) return
26
- if ( compositionMap . get ( input ) ) return
25
+ if ( isComposing ) return
27
26
const list = document . getElementById ( input . getAttribute ( 'aria-owns' ) || '' )
28
27
if ( ! list ) return
29
28
@@ -118,7 +117,7 @@ function clearSelection(list): void {
118
117
function trackComposition ( event : Event ) : void {
119
118
const input = event . currentTarget
120
119
if ( ! ( input instanceof HTMLTextAreaElement || input instanceof HTMLInputElement ) ) return
121
- compositionMap . set ( input , event . type === 'compositionstart' )
120
+ isComposing = event . type === 'compositionstart'
122
121
123
122
const list = document . getElementById ( input . getAttribute ( 'aria-owns' ) || '' )
124
123
if ( ! list ) return
0 commit comments