@@ -73,7 +73,7 @@ import { NotebookOverviewRuler } from 'vs/workbench/contrib/notebook/browser/vie
73
73
import { ListTopCellToolbar } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookTopCellToolbar' ;
74
74
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel' ;
75
75
import { CellKind , INotebookSearchOptions , SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
76
- import { NOTEBOOK_EDITOR_EDITABLE , NOTEBOOK_EDITOR_FOCUSED , NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys' ;
76
+ import { NOTEBOOK_CURSOR_NAVIGATION_MODE , NOTEBOOK_EDITOR_EDITABLE , NOTEBOOK_EDITOR_FOCUSED , NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys' ;
77
77
import { INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService' ;
78
78
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService' ;
79
79
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService' ;
@@ -272,6 +272,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
272
272
private readonly _editorFocus : IContextKey < boolean > ;
273
273
private readonly _outputFocus : IContextKey < boolean > ;
274
274
private readonly _editorEditable : IContextKey < boolean > ;
275
+ private readonly _cursorNavMode : IContextKey < boolean > ;
275
276
protected readonly _contributions = new Map < string , INotebookEditorContribution > ( ) ;
276
277
private _scrollBeyondLastLine : boolean ;
277
278
private readonly _insetModifyQueueByOutputId = new SequencerByKey < string > ( ) ;
@@ -313,16 +314,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
313
314
return this . _renderedEditors . get ( focused ) ;
314
315
}
315
316
316
- private _cursorNavigationMode : boolean = false ;
317
- get cursorNavigationMode ( ) : boolean {
318
- return this . _cursorNavigationMode ;
319
- }
320
-
321
- set cursorNavigationMode ( v : boolean ) {
322
- this . _cursorNavigationMode = v ;
323
- }
324
-
325
-
326
317
get visibleRanges ( ) {
327
318
return this . _list . visibleRanges || [ ] ;
328
319
}
@@ -443,6 +434,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
443
434
this . _editorFocus = NOTEBOOK_EDITOR_FOCUSED . bindTo ( this . scopedContextKeyService ) ;
444
435
this . _outputFocus = NOTEBOOK_OUTPUT_FOCUSED . bindTo ( this . scopedContextKeyService ) ;
445
436
this . _editorEditable = NOTEBOOK_EDITOR_EDITABLE . bindTo ( this . scopedContextKeyService ) ;
437
+ this . _cursorNavMode = NOTEBOOK_CURSOR_NAVIGATION_MODE . bindTo ( this . scopedContextKeyService ) ;
446
438
447
439
this . _editorEditable . set ( ! creationOptions . isReadOnly ) ;
448
440
@@ -962,10 +954,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
962
954
return nls . localize ( 'notebookTreeAriaLabel' , "Notebook" ) ;
963
955
}
964
956
} ,
965
- focusNextPreviousDelegate : {
966
- onFocusNext : ( applyFocusNext : ( ) => void ) => this . _updateForCursorNavigationMode ( applyFocusNext ) ,
967
- onFocusPrevious : ( applyFocusPrevious : ( ) => void ) => this . _updateForCursorNavigationMode ( applyFocusPrevious ) ,
968
- }
969
957
} ,
970
958
) ;
971
959
this . _dndController . setList ( this . _list ) ;
@@ -1013,7 +1001,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
1013
1001
this . _register ( this . _list . onDidChangeFocus ( _e => {
1014
1002
this . _onDidChangeActiveEditor . fire ( this ) ;
1015
1003
this . _onDidChangeActiveCell . fire ( ) ;
1016
- this . _cursorNavigationMode = false ;
1004
+ this . _cursorNavMode . set ( false ) ;
1017
1005
} ) ) ;
1018
1006
1019
1007
this . _register ( this . _list . onContextMenu ( e => {
@@ -1077,23 +1065,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
1077
1065
} ) ) ;
1078
1066
}
1079
1067
1080
- private async _updateForCursorNavigationMode ( applyFocusChange : ( ) => void ) : Promise < void > {
1081
- if ( this . _cursorNavigationMode ) {
1082
- // Will fire onDidChangeFocus, resetting the state to Container
1083
- applyFocusChange ( ) ;
1084
-
1085
- const newFocusedCell = this . _list . getFocusedElements ( ) [ 0 ] ;
1086
- if ( newFocusedCell . cellKind === CellKind . Code || newFocusedCell . getEditState ( ) === CellEditState . Editing ) {
1087
- await this . focusNotebookCell ( newFocusedCell , 'editor' ) ;
1088
- } else {
1089
- // Reset to "Editor", the state has not been consumed
1090
- this . _cursorNavigationMode = true ;
1091
- }
1092
- } else {
1093
- applyFocusChange ( ) ;
1094
- }
1095
- }
1096
-
1097
1068
getDomNode ( ) {
1098
1069
return this . _overlayContainer ;
1099
1070
}
@@ -2353,6 +2324,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
2353
2324
cell . focusMode = CellFocusMode . Editor ;
2354
2325
if ( ! options ?. skipReveal ) {
2355
2326
if ( typeof options ?. focusEditorLine === 'number' ) {
2327
+ this . _cursorNavMode . set ( true ) ;
2356
2328
await this . revealLineInViewAsync ( cell , options . focusEditorLine ) ;
2357
2329
const editor = this . _renderedEditors . get ( cell ) ! ;
2358
2330
const focusEditorLine = options . focusEditorLine ! ;
@@ -2404,7 +2376,12 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
2404
2376
this . focusElement ( cell ) ;
2405
2377
this . _cellFocusAria ( cell , focusItem ) ;
2406
2378
if ( ! options ?. skipReveal ) {
2407
- this . revealInCenterIfOutsideViewport ( cell ) ;
2379
+ if ( typeof options ?. focusEditorLine === 'number' ) {
2380
+ this . _cursorNavMode . set ( true ) ;
2381
+ this . revealInView ( cell ) ;
2382
+ } else {
2383
+ this . revealInCenterIfOutsideViewport ( cell ) ;
2384
+ }
2408
2385
}
2409
2386
this . _list . focusView ( ) ;
2410
2387
}
0 commit comments