5
5
6
6
import { timeout } from 'vs/base/common/async' ;
7
7
import { KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
8
+ import { isEqual } from 'vs/base/common/resources' ;
9
+ import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
8
10
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions' ;
9
11
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
10
12
import { localize } from 'vs/nls' ;
@@ -16,8 +18,10 @@ import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkey
16
18
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
17
19
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
18
20
import { Registry } from 'vs/platform/registry/common/platform' ;
21
+ import { InteractiveEditorController } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController' ;
22
+ import { CTX_INTERACTIVE_EDITOR_FOCUSED , CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor' ;
19
23
import { INotebookActionContext , INotebookCellActionContext , NotebookAction , NotebookCellAction , NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT } from 'vs/workbench/contrib/notebook/browser/controller/coreActions' ;
20
- import { CellEditState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
24
+ import { CellEditState , ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
21
25
import { CellKind , NOTEBOOK_EDITOR_CURSOR_BOUNDARY } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
22
26
import { NOTEBOOK_CELL_HAS_OUTPUTS , NOTEBOOK_CELL_MARKDOWN_EDIT_MODE , NOTEBOOK_CELL_TYPE , NOTEBOOK_CURSOR_NAVIGATION_MODE , NOTEBOOK_EDITOR_FOCUSED , NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys' ;
23
27
@@ -33,6 +37,17 @@ const NOTEBOOK_CURSOR_PAGEUP_SELECT_COMMAND_ID = 'notebook.cell.cursorPageUpSele
33
37
const NOTEBOOK_CURSOR_PAGEDOWN_COMMAND_ID = 'notebook.cell.cursorPageDown' ;
34
38
const NOTEBOOK_CURSOR_PAGEDOWN_SELECT_COMMAND_ID = 'notebook.cell.cursorPageDownSelect' ;
35
39
40
+ function findTargetCellEditor ( context : INotebookCellActionContext , targetCell : ICellViewModel ) {
41
+ let foundEditor : ICodeEditor | undefined = undefined ;
42
+ for ( const [ , codeEditor ] of context . notebookEditor . codeEditors ) {
43
+ if ( isEqual ( codeEditor . getModel ( ) ?. uri , targetCell . uri ) ) {
44
+ foundEditor = codeEditor ;
45
+ break ;
46
+ }
47
+ }
48
+
49
+ return foundEditor ;
50
+ }
36
51
37
52
registerAction2 ( class FocusNextCellAction extends NotebookCellAction {
38
53
constructor ( ) {
@@ -51,6 +66,7 @@ registerAction2(class FocusNextCellAction extends NotebookCellAction {
51
66
NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'top' ) ,
52
67
NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'none' ) ,
53
68
) ,
69
+ EditorContextKeys . isEmbeddedDiffEditor . negate ( )
54
70
) ,
55
71
primary : KeyCode . DownArrow ,
56
72
weight : NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT , // code cell keybinding, focus inside editor: lower weight to not override suggest widget
@@ -63,7 +79,8 @@ registerAction2(class FocusNextCellAction extends NotebookCellAction {
63
79
ContextKeyExpr . and (
64
80
NOTEBOOK_CELL_TYPE . isEqualTo ( 'markup' ) ,
65
81
NOTEBOOK_CELL_MARKDOWN_EDIT_MODE . isEqualTo ( false ) ,
66
- NOTEBOOK_CURSOR_NAVIGATION_MODE )
82
+ NOTEBOOK_CURSOR_NAVIGATION_MODE ) ,
83
+ EditorContextKeys . isEmbeddedDiffEditor . negate ( )
67
84
) ,
68
85
primary : KeyCode . DownArrow ,
69
86
weight : KeybindingWeight . WorkbenchContrib , // markdown keybinding, focus on list: higher weight to override list.focusDown
@@ -73,6 +90,39 @@ registerAction2(class FocusNextCellAction extends NotebookCellAction {
73
90
primary : KeyMod . CtrlCmd | KeyCode . DownArrow ,
74
91
mac : { primary : KeyMod . WinCtrl | KeyMod . CtrlCmd | KeyCode . DownArrow , } ,
75
92
weight : KeybindingWeight . WorkbenchContrib
93
+ } ,
94
+ {
95
+ when : ContextKeyExpr . and (
96
+ NOTEBOOK_EDITOR_FOCUSED ,
97
+ CONTEXT_ACCESSIBILITY_MODE_ENABLED . negate ( ) ,
98
+ ContextKeyExpr . equals ( 'config.notebook.navigation.allowNavigateToSurroundingCells' , true ) ,
99
+ ContextKeyExpr . and (
100
+ ContextKeyExpr . has ( InputFocusedContextKey ) ,
101
+ NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'top' ) ,
102
+ NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'none' ) ,
103
+ ) ,
104
+ CTX_INTERACTIVE_EDITOR_FOCUSED ,
105
+ CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST ,
106
+ EditorContextKeys . isEmbeddedDiffEditor . negate ( )
107
+ ) ,
108
+ primary : KeyCode . DownArrow ,
109
+ weight : KeybindingWeight . EditorCore
110
+ } ,
111
+ {
112
+ when : ContextKeyExpr . and (
113
+ NOTEBOOK_EDITOR_FOCUSED ,
114
+ CONTEXT_ACCESSIBILITY_MODE_ENABLED . negate ( ) ,
115
+ ContextKeyExpr . equals ( 'config.notebook.navigation.allowNavigateToSurroundingCells' , true ) ,
116
+ ContextKeyExpr . and (
117
+ NOTEBOOK_CELL_TYPE . isEqualTo ( 'markup' ) ,
118
+ NOTEBOOK_CELL_MARKDOWN_EDIT_MODE . isEqualTo ( false ) ,
119
+ NOTEBOOK_CURSOR_NAVIGATION_MODE ) ,
120
+ CTX_INTERACTIVE_EDITOR_FOCUSED ,
121
+ CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST ,
122
+ EditorContextKeys . isEmbeddedDiffEditor . negate ( )
123
+ ) ,
124
+ primary : KeyCode . DownArrow ,
125
+ weight : KeybindingWeight . EditorCore
76
126
}
77
127
]
78
128
} ) ;
@@ -92,9 +142,17 @@ registerAction2(class FocusNextCellAction extends NotebookCellAction {
92
142
return ;
93
143
}
94
144
95
- const newCell = editor . cellAt ( idx + 1 ) ;
96
- const newFocusMode = newCell . cellKind === CellKind . Markup && newCell . getEditState ( ) === CellEditState . Preview ? 'container' : 'editor' ;
97
- await editor . focusNotebookCell ( newCell , newFocusMode , { focusEditorLine : 1 } ) ;
145
+ const focusEditorLine = activeCell . textBuffer . getLineCount ( ) ;
146
+ const targetCell = ( context . cell ?? context . selectedCells ?. [ 0 ] ) ;
147
+ const foundEditor : ICodeEditor | undefined = targetCell ? findTargetCellEditor ( context , targetCell ) : undefined ;
148
+
149
+ if ( foundEditor && foundEditor . hasTextFocus ( ) && InteractiveEditorController . get ( foundEditor ) ?. getWidgetPosition ( ) ?. lineNumber === focusEditorLine ) {
150
+ InteractiveEditorController . get ( foundEditor ) ?. focus ( ) ;
151
+ } else {
152
+ const newCell = editor . cellAt ( idx + 1 ) ;
153
+ const newFocusMode = newCell . cellKind === CellKind . Markup && newCell . getEditState ( ) === CellEditState . Preview ? 'container' : 'editor' ;
154
+ await editor . focusNotebookCell ( newCell , newFocusMode , { focusEditorLine : 1 } ) ;
155
+ }
98
156
}
99
157
} ) ;
100
158
@@ -117,6 +175,7 @@ registerAction2(class FocusPreviousCellAction extends NotebookCellAction {
117
175
NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'bottom' ) ,
118
176
NOTEBOOK_EDITOR_CURSOR_BOUNDARY . notEqualsTo ( 'none' ) ,
119
177
) ,
178
+ EditorContextKeys . isEmbeddedDiffEditor . negate ( )
120
179
) ,
121
180
primary : KeyCode . UpArrow ,
122
181
weight : NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT , // code cell keybinding, focus inside editor: lower weight to not override suggest widget
@@ -130,7 +189,8 @@ registerAction2(class FocusPreviousCellAction extends NotebookCellAction {
130
189
NOTEBOOK_CELL_TYPE . isEqualTo ( 'markup' ) ,
131
190
NOTEBOOK_CELL_MARKDOWN_EDIT_MODE . isEqualTo ( false ) ,
132
191
NOTEBOOK_CURSOR_NAVIGATION_MODE
133
- )
192
+ ) ,
193
+ EditorContextKeys . isEmbeddedDiffEditor . negate ( )
134
194
) ,
135
195
primary : KeyCode . UpArrow ,
136
196
weight : KeybindingWeight . WorkbenchContrib , // markdown keybinding, focus on list: higher weight to override list.focusDown
@@ -155,7 +215,14 @@ registerAction2(class FocusPreviousCellAction extends NotebookCellAction {
155
215
156
216
const newCell = editor . cellAt ( idx - 1 ) ;
157
217
const newFocusMode = newCell . cellKind === CellKind . Markup && newCell . getEditState ( ) === CellEditState . Preview ? 'container' : 'editor' ;
158
- await editor . focusNotebookCell ( newCell , newFocusMode , { focusEditorLine : newCell . textBuffer . getLineCount ( ) } ) ;
218
+ const focusEditorLine = newCell . textBuffer . getLineCount ( ) ;
219
+ await editor . focusNotebookCell ( newCell , newFocusMode , { focusEditorLine : focusEditorLine } ) ;
220
+
221
+ const foundEditor : ICodeEditor | undefined = findTargetCellEditor ( context , newCell ) ;
222
+
223
+ if ( foundEditor && InteractiveEditorController . get ( foundEditor ) ?. getWidgetPosition ( ) ?. lineNumber === focusEditorLine ) {
224
+ InteractiveEditorController . get ( foundEditor ) ?. focus ( ) ;
225
+ }
159
226
}
160
227
} ) ;
161
228
0 commit comments