@@ -142,6 +142,7 @@ export class InteractiveCell extends React.Component<IInteractiveCellProps> {
142
142
ref = { this . wrapperRef }
143
143
tabIndex = { 0 }
144
144
onKeyDown = { this . onKeyDown }
145
+ onKeyUp = { this . onKeyUp }
145
146
onClick = { this . onMouseClick }
146
147
>
147
148
< div className = { cellOuterClass } >
@@ -354,24 +355,47 @@ export class InteractiveCell extends React.Component<IInteractiveCellProps> {
354
355
}
355
356
} ;
356
357
358
+ private onKeyUp = ( event : React . KeyboardEvent < HTMLDivElement > ) => {
359
+ // Handle keydown events for the entire cell
360
+ if ( this . getCell ( ) . id === Identifiers . EditCellId ) {
361
+ const e : IKeyboardEvent = {
362
+ code : event . key ,
363
+ shiftKey : event . shiftKey ,
364
+ ctrlKey : event . ctrlKey ,
365
+ metaKey : event . metaKey ,
366
+ altKey : event . altKey ,
367
+ target : event . target as HTMLDivElement ,
368
+ stopPropagation : ( ) => event . stopPropagation ( ) ,
369
+ preventDefault : ( ) => event . preventDefault ( )
370
+ } ;
371
+ this . onEditCellKeyUp ( Identifiers . EditCellId , e ) ;
372
+ }
373
+ } ;
374
+
357
375
private onEditCellKeyDown = ( _cellId : string , e : IKeyboardEvent ) => {
358
- if ( e . code === 'Tab' && e . shiftKey ) {
359
- this . editCellShiftTab ( e ) ;
360
- } else if ( e . code === 'Enter' && e . shiftKey ) {
376
+ if ( e . code === 'Enter' && e . shiftKey ) {
361
377
this . editCellSubmit ( e ) ;
362
378
} else if ( e . code === 'NumpadEnter' && e . shiftKey ) {
363
379
this . editCellSubmit ( e ) ;
364
380
} else if ( e . code === 'KeyU' && e . ctrlKey && e . editorInfo && ! e . editorInfo . isSuggesting ) {
365
381
e . editorInfo . clear ( ) ;
366
382
e . stopPropagation ( ) ;
367
383
e . preventDefault ( ) ;
368
- } else if ( e . code === 'Escape' && e . editorInfo && ! e . editorInfo . isSuggesting ) {
384
+ } else if ( e . code === 'Escape' && ! e . shiftKey && e . editorInfo && ! e . editorInfo . isSuggesting ) {
369
385
e . editorInfo . clear ( ) ;
370
386
e . stopPropagation ( ) ;
371
387
e . preventDefault ( ) ;
372
388
}
373
389
} ;
374
390
391
+ private onEditCellKeyUp = ( _cellId : string , e : IKeyboardEvent ) => {
392
+ // Special case. Escape + Shift only comes as a key up because shift comes as the
393
+ // key down.
394
+ if ( e . code === 'Escape' && e . shiftKey ) {
395
+ this . editCellShiftEscape ( e ) ;
396
+ }
397
+ } ;
398
+
375
399
private editCellSubmit ( e : IKeyboardEvent ) {
376
400
if ( e . editorInfo && e . editorInfo . contents ) {
377
401
// Prevent shift+enter from turning into a enter
@@ -409,9 +433,9 @@ export class InteractiveCell extends React.Component<IInteractiveCellProps> {
409
433
}
410
434
}
411
435
412
- private editCellShiftTab = ( e : IKeyboardEvent ) => {
436
+ private editCellShiftEscape = ( e : IKeyboardEvent ) => {
413
437
const focusedElement = document . activeElement ;
414
- if ( focusedElement !== null && e . editorInfo && ! e . editorInfo . isSuggesting ) {
438
+ if ( focusedElement !== null ) {
415
439
const nextTabStop = this . findTabStop ( 1 , focusedElement ) ;
416
440
if ( nextTabStop ) {
417
441
e . stopPropagation ( ) ;
0 commit comments