@@ -40,6 +40,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
40
40
private stateController : NativeEditorStateController ;
41
41
private initialCellDivs : ( HTMLDivElement | null ) [ ] = [ ] ;
42
42
private debounceUpdateVisibleCells = debounce ( this . updateVisibleCells . bind ( this ) , 100 ) ;
43
+ private pressedDOnce = false ;
43
44
44
45
constructor ( props : INativeEditorProps ) {
45
46
super ( props ) ;
@@ -281,68 +282,114 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
281
282
}
282
283
}
283
284
284
- // tslint:disable-next-line: cyclomatic-complexity
285
- private keyDownCell = ( cellId : string , e : IKeyboardEvent ) => {
285
+ // tslint:disable-next-line: cyclomatic-complexity max-func-body-length
286
+ private keyDownCell = async ( cellId : string , e : IKeyboardEvent ) => {
286
287
switch ( e . code ) {
287
288
case 'ArrowUp' :
289
+ this . pressedDOnce = false ;
288
290
if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isFirstLine && ! e . editorInfo . isSuggesting ) {
289
291
this . arrowUpFromCell ( cellId , e ) ;
290
292
} else if ( ! this . state . focusedCell ) {
291
293
this . arrowUpFromCell ( cellId , e ) ;
292
294
}
293
295
break ;
294
-
295
296
case 'ArrowDown' :
297
+ this . pressedDOnce = false ;
296
298
if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isLastLine && ! e . editorInfo . isSuggesting ) {
297
299
this . arrowDownFromCell ( cellId , e ) ;
298
300
} else if ( ! this . state . focusedCell ) {
299
301
this . arrowDownFromCell ( cellId , e ) ;
300
302
}
301
303
break ;
302
-
303
304
case 'Escape' :
305
+ this . pressedDOnce = false ;
304
306
if ( this . state . focusedCell && e . editorInfo && ! e . editorInfo . isSuggesting ) {
305
307
this . escapeCell ( this . state . focusedCell , e ) ;
306
308
}
307
309
break ;
308
-
309
310
case 'y' :
311
+ this . pressedDOnce = false ;
310
312
if ( ! this . state . focusedCell && this . state . selectedCell ) {
311
313
e . stopPropagation ( ) ;
312
314
this . stateController . changeCellType ( this . state . selectedCell , 'code' ) ;
313
315
}
314
316
break ;
315
-
316
317
case 'm' :
318
+ this . pressedDOnce = false ;
317
319
if ( ! this . state . focusedCell && this . state . selectedCell ) {
318
320
e . stopPropagation ( ) ;
319
321
this . stateController . changeCellType ( this . state . selectedCell , 'markdown' ) ;
320
322
}
321
323
break ;
322
-
323
324
case 'l' :
325
+ this . pressedDOnce = false ;
324
326
if ( ! this . state . focusedCell && this . state . selectedCell ) {
325
327
e . stopPropagation ( ) ;
326
328
this . stateController . toggleLineNumbers ( this . state . selectedCell ) ;
327
329
}
328
330
break ;
329
-
330
331
case 'o' :
332
+ this . pressedDOnce = false ;
331
333
if ( ! this . state . focusedCell && this . state . selectedCell ) {
332
334
e . stopPropagation ( ) ;
333
335
this . stateController . toggleOutput ( this . state . selectedCell ) ;
334
336
}
335
337
break ;
336
-
337
338
case 'Enter' :
339
+ this . pressedDOnce = false ;
338
340
if ( e . shiftKey ) {
339
- this . submitCell ( cellId , e ) ;
341
+ this . submitCell ( cellId , e , true ) ;
342
+ } else if ( e . ctrlKey ) {
343
+ this . submitCell ( cellId , e , false ) ;
344
+ } else if ( e . altKey ) {
345
+ this . submitCell ( cellId , e , false ) ;
346
+ this . stateController . insertBelow ( cellId , true ) ;
340
347
} else {
341
348
this . enterCell ( cellId , e ) ;
342
349
}
343
350
break ;
344
-
351
+ case 'd' :
352
+ if ( this . pressedDOnce ) {
353
+ this . stateController . deleteCell ( cellId ) ;
354
+ this . pressedDOnce = false ;
355
+ } else {
356
+ this . pressedDOnce = true ;
357
+ }
358
+ break ;
359
+ case 'a' :
360
+ this . pressedDOnce = false ;
361
+ if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isLastLine && ! e . editorInfo . isSuggesting ) {
362
+ this . stateController . insertAbove ( cellId , true ) ;
363
+ } else if ( ! this . state . focusedCell ) {
364
+ this . stateController . insertAbove ( cellId , true ) ;
365
+ }
366
+ break ;
367
+ case 'b' :
368
+ this . pressedDOnce = false ;
369
+ if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isLastLine && ! e . editorInfo . isSuggesting ) {
370
+ this . stateController . insertBelow ( cellId , true ) ;
371
+ } else if ( ! this . state . focusedCell ) {
372
+ this . stateController . insertBelow ( cellId , true ) ;
373
+ }
374
+ break ;
375
+ case 'j' :
376
+ this . pressedDOnce = false ;
377
+ if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isFirstLine && ! e . editorInfo . isSuggesting ) {
378
+ this . arrowUpFromCell ( cellId , e ) ;
379
+ } else if ( ! this . state . focusedCell ) {
380
+ this . arrowUpFromCell ( cellId , e ) ;
381
+ }
382
+ break ;
383
+ case 'k' :
384
+ this . pressedDOnce = false ;
385
+ if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isFirstLine && ! e . editorInfo . isSuggesting ) {
386
+ this . arrowDownFromCell ( cellId , e ) ;
387
+ } else if ( ! this . state . focusedCell ) {
388
+ this . arrowDownFromCell ( cellId , e ) ;
389
+ }
390
+ break ;
345
391
default :
392
+ this . pressedDOnce = false ;
346
393
break ;
347
394
}
348
395
}
@@ -361,7 +408,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
361
408
}
362
409
}
363
410
364
- private submitCell = ( cellId : string , e : IKeyboardEvent ) => {
411
+ private submitCell = ( cellId : string , e : IKeyboardEvent , moveToNextCell : boolean ) => {
365
412
let content : string | undefined ;
366
413
const cellVM = this . findCellViewModel ( cellId ) ;
367
414
@@ -382,7 +429,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
382
429
}
383
430
384
431
// If this is not the edit cell, move to our next cell
385
- if ( cellId !== Identifiers . EditCellId ) {
432
+ if ( cellId !== Identifiers . EditCellId && moveToNextCell ) {
386
433
const nextCell = this . getNextCellId ( cellId ) ;
387
434
if ( nextCell ) {
388
435
this . stateController . selectCell ( nextCell , undefined ) ;
@@ -439,6 +486,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
439
486
}
440
487
441
488
private clickCell = ( cellId : string ) => {
489
+ this . pressedDOnce = false ;
442
490
const focusedCell = cellId === this . state . focusedCell ? cellId : undefined ;
443
491
this . stateController . selectCell ( cellId , focusedCell ) ;
444
492
}
@@ -472,6 +520,24 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
472
520
// }
473
521
// }
474
522
523
+ // private pasteFromClipboard = (cellId: string) => {
524
+ // const editedCells = this.state.cellVMs;
525
+ // const index = editedCells.findIndex(x => x.cell.id === cellId) + 1;
526
+
527
+ // if (index > -1) {
528
+ // const textArea = document.createElement('textarea');
529
+ // document.body.appendChild(textArea);
530
+ // textArea.select();
531
+ // document.execCommand('Paste');
532
+ // editedCells[index].cell.data.source = textArea.value.split(/\r?\n/);
533
+ // textArea.remove();
534
+ // }
535
+
536
+ // this.setState({
537
+ // cellVMs: editedCells
538
+ // });
539
+ // }
540
+
475
541
private moveCellUp = ( cellId ?: string ) => {
476
542
if ( this . contentPanelRef . current && cellId ) {
477
543
const wasFocused = this . state . focusedCell ;
0 commit comments