@@ -165,7 +165,27 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
165165 cm . display . input . textarea . value &&
166166 cm . display . input . textarea . value . slice ( - 1 ) . match ( filter )
167167 ) {
168- cm . showHint ( { hint : this . server . getHint , completeSingle : false } ) ;
168+ cm . showHint ( {
169+ hint : this . server . getHint ,
170+ completeSingle : false ,
171+ customKeys : {
172+ Up : ( _cm , handle ) => handle . moveFocus ( - 1 ) ,
173+ Down : ( _cm , handle ) => handle . moveFocus ( 1 ) ,
174+ PageUp : ( _cm , handle ) =>
175+ handle . moveFocus ( - handle . menuSize ( ) + 1 , true ) ,
176+ PageDown : ( _cm , handle ) =>
177+ handle . moveFocus ( handle . menuSize ( ) - 1 , true ) ,
178+ Home : ( _cm , handle ) => handle . setFocus ( 0 ) ,
179+ End : ( _cm , handle ) => handle . setFocus ( handle . length - 1 ) ,
180+ Enter : ( _cm , handle ) => handle . pick ( ) ,
181+ Tab : ( _cm , handle ) => handle . pick ( ) ,
182+ // We disable this in vimMode, because we want vim to go from
183+ // insert mode to normal mode when you press enter. This does that
184+ ...( settings . vimMode
185+ ? { }
186+ : { Esc : ( _cm , handle ) => handle . close ( ) } ) ,
187+ } ,
188+ } ) ;
169189 }
170190 }
171191 } ;
@@ -274,8 +294,10 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
274294
275295 changeCode = ( code : string = '' ) => {
276296 const pos = this . codemirror . getCursor ( ) ;
277- this . codemirror . setValue ( code ) ;
278297 this . codemirror . setCursor ( pos ) ;
298+ if ( this . getCode ( ) !== code ) {
299+ this . codemirror . setValue ( code ) ;
300+ }
279301 } ;
280302
281303 getMode = async ( title : string ) => {
@@ -345,7 +367,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
345367 highlightLines ( this . codemirror , this . props . highlightedLines ) ;
346368 }
347369
348- this . codemirror . on ( 'change ' , this . handleChange ) ;
370+ this . codemirror . on ( 'changes ' , this . handleChange ) ;
349371 this . changeSettings ( this . settings ) ;
350372 } ;
351373
0 commit comments