Skip to content

Commit 8edb01d

Browse files
committed
feat: add cmd+enter command for running focused block
1 parent 614334b commit 8edb01d

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070
"key": "escape",
7171
"when": "isCompositeNotebook && !editorHoverVisible && !suggestWidgetVisible && !isComposing && !inSnippetMode && !exceptionWidgetVisible && !selectionAnchorSet && !LinkedEditingInputVisible && !renameInputVisible && !editorHasSelection && !accessibilityHelpWidgetVisible && !breakpointWidgetVisible && !findWidgetVisible && !markersNavigationVisible && !parameterHintsVisible && !editorHasMultipleSelections && !notificationToastsVisible && !notebookEditorFocused && !inlineChatVisible",
7272
"command": "interactive.input.clear"
73+
},
74+
{
75+
"key": "cmd+enter",
76+
"mac": "cmd+enter",
77+
"win": "ctrl+enter",
78+
"linux": "ctrl+enter",
79+
"when": "notebookEditorFocused && !findInputFocussed && !replaceInputFocussed",
80+
"command": "jupyter.notebookeditor.runfocusedcell"
7381
}
7482
],
7583
"commands": [
@@ -478,6 +486,12 @@
478486
"category": "Notebook",
479487
"enablement": "!jupyter.webExtension"
480488
},
489+
{
490+
"command": "jupyter.notebookeditor.runfocusedcell",
491+
"title": "Run Focused Cell",
492+
"category": "Notebook",
493+
"enablement": "notebookEditorFocused"
494+
},
481495
{
482496
"command": "jupyter.expandallcells",
483497
"title": "%jupyter.command.jupyter.expandallcells.title%",

src/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface ICommandNameArgumentTypeMapping {
5858
[DSCommands.RestartKernelAndRunUpToSelectedCell]: [{ notebookEditor: { notebookUri: Uri } } | undefined];
5959
[DSCommands.NotebookEditorRemoveAllCells]: [];
6060
[DSCommands.NotebookEditorRunAllCells]: [];
61+
[DSCommands.NotebookEditorRunFocusedCell]: [];
6162
[DSCommands.NotebookEditorAddCellBelow]: [];
6263
[DSCommands.ExpandAllCells]: [];
6364
[DSCommands.CollapseAllCells]: [];

src/notebooks/notebookCommandListener.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export class NotebookCommandListener implements INotebookCommandHandler, IExtens
6868
this.disposableRegistry.push(
6969
commands.registerCommand(Commands.NotebookEditorRunAllCells, () => this.runAllCells())
7070
);
71+
this.disposableRegistry.push(
72+
commands.registerCommand(Commands.NotebookEditorRunFocusedCell, () => this.runFocusedCell())
73+
);
7174
this.disposableRegistry.push(
7275
commands.registerCommand(Commands.NotebookEditorAddCellBelow, () => this.addCellBelow())
7376
);
@@ -115,6 +118,27 @@ export class NotebookCommandListener implements INotebookCommandHandler, IExtens
115118
}
116119
}
117120

121+
private runFocusedCell() {
122+
const editor = window.activeNotebookEditor;
123+
if (!editor) {
124+
return;
125+
}
126+
127+
// Get the first selection range
128+
const range = editor.selections[0];
129+
if (!range) {
130+
return;
131+
}
132+
133+
// Execute the cell at the start of the selection
134+
commands
135+
.executeCommand('notebook.cell.execute', {
136+
ranges: [{ start: range.start, end: range.start + 1 }],
137+
document: editor.notebook.uri
138+
})
139+
.then(noop, noop);
140+
}
141+
118142
private addCellBelow() {
119143
if (window.activeNotebookEditor) {
120144
commands.executeCommand('notebook.cell.insertCodeCellBelow').then(noop, noop);

src/platform/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export namespace Commands {
189189
export const NotebookEditorRemoveAllCells = 'jupyter.notebookeditor.removeallcells';
190190
export const NotebookEditorRunAllCells = 'jupyter.notebookeditor.runallcells';
191191
export const NotebookEditorRunSelectedCell = 'jupyter.notebookeditor.runselectedcell';
192+
export const NotebookEditorRunFocusedCell = 'jupyter.notebookeditor.runfocusedcell';
192193
export const NotebookEditorAddCellBelow = 'jupyter.notebookeditor.addcellbelow';
193194
export const ExpandAllCells = 'jupyter.expandallcells';
194195
export const CollapseAllCells = 'jupyter.collapseallcells';

0 commit comments

Comments
 (0)