@@ -40,6 +40,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
4040 private stateController : NativeEditorStateController ;
4141 private initialCellDivs : ( HTMLDivElement | null ) [ ] = [ ] ;
4242 private debounceUpdateVisibleCells = debounce ( this . updateVisibleCells . bind ( this ) , 100 ) ;
43+ private pressedDOnce = false ;
4344
4445 constructor ( props : INativeEditorProps ) {
4546 super ( props ) ;
@@ -281,68 +282,114 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
281282 }
282283 }
283284
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 ) => {
286287 switch ( e . code ) {
287288 case 'ArrowUp' :
289+ this . pressedDOnce = false ;
288290 if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isFirstLine && ! e . editorInfo . isSuggesting ) {
289291 this . arrowUpFromCell ( cellId , e ) ;
290292 } else if ( ! this . state . focusedCell ) {
291293 this . arrowUpFromCell ( cellId , e ) ;
292294 }
293295 break ;
294-
295296 case 'ArrowDown' :
297+ this . pressedDOnce = false ;
296298 if ( this . state . focusedCell === cellId && e . editorInfo && e . editorInfo . isLastLine && ! e . editorInfo . isSuggesting ) {
297299 this . arrowDownFromCell ( cellId , e ) ;
298300 } else if ( ! this . state . focusedCell ) {
299301 this . arrowDownFromCell ( cellId , e ) ;
300302 }
301303 break ;
302-
303304 case 'Escape' :
305+ this . pressedDOnce = false ;
304306 if ( this . state . focusedCell && e . editorInfo && ! e . editorInfo . isSuggesting ) {
305307 this . escapeCell ( this . state . focusedCell , e ) ;
306308 }
307309 break ;
308-
309310 case 'y' :
311+ this . pressedDOnce = false ;
310312 if ( ! this . state . focusedCell && this . state . selectedCell ) {
311313 e . stopPropagation ( ) ;
312314 this . stateController . changeCellType ( this . state . selectedCell , 'code' ) ;
313315 }
314316 break ;
315-
316317 case 'm' :
318+ this . pressedDOnce = false ;
317319 if ( ! this . state . focusedCell && this . state . selectedCell ) {
318320 e . stopPropagation ( ) ;
319321 this . stateController . changeCellType ( this . state . selectedCell , 'markdown' ) ;
320322 }
321323 break ;
322-
323324 case 'l' :
325+ this . pressedDOnce = false ;
324326 if ( ! this . state . focusedCell && this . state . selectedCell ) {
325327 e . stopPropagation ( ) ;
326328 this . stateController . toggleLineNumbers ( this . state . selectedCell ) ;
327329 }
328330 break ;
329-
330331 case 'o' :
332+ this . pressedDOnce = false ;
331333 if ( ! this . state . focusedCell && this . state . selectedCell ) {
332334 e . stopPropagation ( ) ;
333335 this . stateController . toggleOutput ( this . state . selectedCell ) ;
334336 }
335337 break ;
336-
337338 case 'Enter' :
339+ this . pressedDOnce = false ;
338340 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 ) ;
340347 } else {
341348 this . enterCell ( cellId , e ) ;
342349 }
343350 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 ;
345391 default :
392+ this . pressedDOnce = false ;
346393 break ;
347394 }
348395 }
@@ -361,7 +408,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
361408 }
362409 }
363410
364- private submitCell = ( cellId : string , e : IKeyboardEvent ) => {
411+ private submitCell = ( cellId : string , e : IKeyboardEvent , moveToNextCell : boolean ) => {
365412 let content : string | undefined ;
366413 const cellVM = this . findCellViewModel ( cellId ) ;
367414
@@ -382,7 +429,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
382429 }
383430
384431 // If this is not the edit cell, move to our next cell
385- if ( cellId !== Identifiers . EditCellId ) {
432+ if ( cellId !== Identifiers . EditCellId && moveToNextCell ) {
386433 const nextCell = this . getNextCellId ( cellId ) ;
387434 if ( nextCell ) {
388435 this . stateController . selectCell ( nextCell , undefined ) ;
@@ -439,6 +486,7 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
439486 }
440487
441488 private clickCell = ( cellId : string ) => {
489+ this . pressedDOnce = false ;
442490 const focusedCell = cellId === this . state . focusedCell ? cellId : undefined ;
443491 this . stateController . selectCell ( cellId , focusedCell ) ;
444492 }
@@ -472,6 +520,24 @@ export class NativeEditor extends React.Component<INativeEditorProps, IMainState
472520 // }
473521 // }
474522
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+
475541 private moveCellUp = ( cellId ?: string ) => {
476542 if ( this . contentPanelRef . current && cellId ) {
477543 const wasFocused = this . state . focusedCell ;
0 commit comments