@@ -12,8 +12,8 @@ import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebook
1212import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
1313import { NOTEBOOK_EDITOR_FOCUSED , NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor' ;
1414import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
15- import { KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
16- import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
15+ import { KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED , CellState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
16+ import { CellKind , NOTEBOOK_EDITOR_CURSOR_BOUNDARY } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
1717import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel' ;
1818
1919registerAction2 ( class extends Action2 {
@@ -153,6 +153,10 @@ registerAction2(class extends Action2 {
153153
154154 let activeCell = editor . getActiveCell ( ) ;
155155 if ( activeCell ) {
156+ if ( activeCell . cellKind === CellKind . Markdown ) {
157+ activeCell . state = CellState . Read ;
158+ }
159+
156160 editor . focusNotebookCell ( activeCell , false ) ;
157161 }
158162 }
@@ -361,3 +365,109 @@ function changeActiveCellToKind(kind: CellKind, accessor: ServicesAccessor): voi
361365 editor . focusNotebookCell ( newCell , false ) ;
362366 editor . deleteNotebookCell ( activeCell ) ;
363367}
368+
369+ function getActiveCell ( accessor : ServicesAccessor ) : [ NotebookEditor , CellViewModel ] | undefined {
370+ const editorService = accessor . get ( IEditorService ) ;
371+ const notebookService = accessor . get ( INotebookService ) ;
372+
373+ const resource = editorService . activeEditor ?. resource ;
374+ if ( ! resource ) {
375+ return ;
376+ }
377+
378+ const editor = getActiveNotebookEditor ( editorService ) ;
379+ if ( ! editor ) {
380+ return ;
381+ }
382+
383+ const notebookProviders = notebookService . getContributedNotebookProviders ( resource ) ;
384+ if ( ! notebookProviders . length ) {
385+ return ;
386+ }
387+
388+ const activeCell = editor . getActiveCell ( ) ;
389+ if ( ! activeCell ) {
390+ return ;
391+ }
392+
393+ return [ editor , activeCell ] ;
394+ }
395+
396+
397+ registerAction2 ( class extends Action2 {
398+ constructor ( ) {
399+ super ( {
400+ id : 'workbench.action.notebook.cursorDown' ,
401+ title : 'Notebook Cursor Move Down' ,
402+ keybinding : {
403+ when : ContextKeyExpr . and ( NOTEBOOK_EDITOR_FOCUSED , ContextKeyExpr . has ( InputFocusedContextKey ) , NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'top' ) , NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'none' ) ) ,
404+ primary : KeyCode . DownArrow ,
405+ weight : KeybindingWeight . WorkbenchContrib
406+ }
407+ } ) ;
408+ }
409+
410+ async run ( accessor : ServicesAccessor ) : Promise < void > {
411+ const activeCellRet = getActiveCell ( accessor ) ;
412+
413+ if ( ! activeCellRet ) {
414+ return ;
415+ }
416+
417+ const [ editor , activeCell ] = activeCellRet ;
418+
419+ const idx = editor . viewModel ?. getViewCellIndex ( activeCell ) ;
420+ if ( typeof idx !== 'number' ) {
421+ return ;
422+ }
423+
424+ const newCell = editor . viewModel ?. viewCells [ idx + 1 ] ;
425+
426+ if ( ! newCell ) {
427+ return ;
428+ }
429+
430+ editor . focusNotebookCell ( newCell , true ) ;
431+ }
432+ } ) ;
433+
434+ registerAction2 ( class extends Action2 {
435+ constructor ( ) {
436+ super ( {
437+ id : 'workbench.action.notebook.cursorUp' ,
438+ title : 'Notebook Cursor Move Up' ,
439+ keybinding : {
440+ when : ContextKeyExpr . and ( NOTEBOOK_EDITOR_FOCUSED , ContextKeyExpr . has ( InputFocusedContextKey ) , NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'bottom' ) , NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'none' ) ) ,
441+ primary : KeyCode . UpArrow ,
442+ weight : KeybindingWeight . WorkbenchContrib
443+ } ,
444+ } ) ;
445+ }
446+
447+ async run ( accessor : ServicesAccessor ) : Promise < void > {
448+ const activeCellRet = getActiveCell ( accessor ) ;
449+
450+ if ( ! activeCellRet ) {
451+ return ;
452+ }
453+
454+ const [ editor , activeCell ] = activeCellRet ;
455+ const idx = editor . viewModel ?. getViewCellIndex ( activeCell ) ;
456+ if ( typeof idx !== 'number' ) {
457+ return ;
458+ }
459+
460+ if ( idx < 1 ) {
461+ // we don't do loop
462+ return ;
463+ }
464+
465+ const newCell = editor . viewModel ?. viewCells [ idx - 1 ] ;
466+
467+ if ( ! newCell ) {
468+ return ;
469+ }
470+
471+ editor . focusNotebookCell ( newCell , true ) ;
472+ }
473+ } ) ;
0 commit comments