@@ -419,12 +419,15 @@ class Editor extends React.Component {
419419 }
420420
421421 showHint ( _cm ) {
422+ if ( ! _cm ) return ;
423+
422424 if ( ! this . props . autocompleteHinter ) {
423425 CodeMirror . showHint ( _cm , ( ) => { } , { } ) ;
424426 return ;
425427 }
426428
427429 let focusedLinkElement = null ;
430+
428431 const setFocusedLinkElement = ( set ) => {
429432 if ( set && ! focusedLinkElement ) {
430433 const activeItemLink = document . querySelector (
@@ -439,6 +442,7 @@ class Editor extends React.Component {
439442 }
440443 }
441444 } ;
445+
442446 const removeFocusedLinkElement = ( ) => {
443447 if ( focusedLinkElement ) {
444448 focusedLinkElement . classList . remove ( 'focused-hint-link' ) ;
@@ -461,12 +465,8 @@ class Editor extends React.Component {
461465 ) ;
462466 if ( activeItemLink ) activeItemLink . click ( ) ;
463467 } ,
464- Right : ( cm , e ) => {
465- setFocusedLinkElement ( true ) ;
466- } ,
467- Left : ( cm , e ) => {
468- removeFocusedLinkElement ( ) ;
469- } ,
468+ Right : ( cm , e ) => setFocusedLinkElement ( true ) ,
469+ Left : ( cm , e ) => removeFocusedLinkElement ( ) ,
470470 Up : ( cm , e ) => {
471471 const onLink = removeFocusedLinkElement ( ) ;
472472 e . moveFocus ( - 1 ) ;
@@ -485,26 +485,28 @@ class Editor extends React.Component {
485485 closeOnUnfocus : false
486486 } ;
487487
488- if ( _cm . options . mode === 'javascript' ) {
489- // JavaScript
490- CodeMirror . showHint (
491- _cm ,
492- ( ) => {
493- const c = _cm . getCursor ( ) ;
494- const token = _cm . getTokenAt ( c ) ;
495- const hints = contextAwareHinter ( _cm , { hinter : this . hinter } ) ;
496- return {
497- list : hints ,
498- from : CodeMirror . Pos ( c . line , token . start ) ,
499- to : CodeMirror . Pos ( c . line , c . ch )
500- } ;
501- } ,
502- hintOptions
503- ) ;
504- } else if ( _cm . options . mode === 'css' ) {
505- // CSS
506- CodeMirror . showHint ( _cm , CodeMirror . hint . css , hintOptions ) ;
507- }
488+ const triggerHints = ( ) => {
489+ if ( _cm . options . mode === 'javascript' ) {
490+ CodeMirror . showHint (
491+ _cm ,
492+ ( ) => {
493+ const c = _cm . getCursor ( ) ;
494+ const token = _cm . getTokenAt ( c ) ;
495+ const hints = contextAwareHinter ( _cm , { hinter : this . hinter } ) ;
496+ return {
497+ list : hints ,
498+ from : CodeMirror . Pos ( c . line , token . start ) ,
499+ to : CodeMirror . Pos ( c . line , c . ch )
500+ } ;
501+ } ,
502+ hintOptions
503+ ) ;
504+ } else if ( _cm . options . mode === 'css' ) {
505+ CodeMirror . showHint ( _cm , CodeMirror . hint . css , hintOptions ) ;
506+ }
507+ } ;
508+
509+ setTimeout ( triggerHints , 0 ) ;
508510 }
509511
510512 showReplace ( ) {
0 commit comments