diff --git a/package.json b/package.json index c73aea4449..5321f9bc86 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,14 @@ "key": "escape", "when": "isCompositeNotebook && !editorHoverVisible && !suggestWidgetVisible && !isComposing && !inSnippetMode && !exceptionWidgetVisible && !selectionAnchorSet && !LinkedEditingInputVisible && !renameInputVisible && !editorHasSelection && !accessibilityHelpWidgetVisible && !breakpointWidgetVisible && !findWidgetVisible && !markersNavigationVisible && !parameterHintsVisible && !editorHasMultipleSelections && !notificationToastsVisible && !notebookEditorFocused && !inlineChatVisible", "command": "interactive.input.clear" + }, + { + "key": "cmd+enter", + "mac": "cmd+enter", + "win": "ctrl+enter", + "linux": "ctrl+enter", + "when": "notebookEditorFocused && !findInputFocussed && !replaceInputFocussed", + "command": "jupyter.notebookeditor.runfocusedcell" } ], "commands": [ @@ -544,6 +552,12 @@ "category": "Notebook", "enablement": "!jupyter.webExtension" }, + { + "command": "jupyter.notebookeditor.runfocusedcell", + "title": "%jupyter.command.jupyter.notebookeditor.runfocusedcell.title%", + "category": "Notebook", + "enablement": "notebookEditorFocused" + }, { "command": "jupyter.expandallcells", "title": "%jupyter.command.jupyter.expandallcells.title%", diff --git a/package.nls.json b/package.nls.json index d24ff31dc2..1d6006666e 100644 --- a/package.nls.json +++ b/package.nls.json @@ -92,6 +92,7 @@ "message": "Add Empty Cell to Notebook File", "comment": ["{Locked='Notebook'}"] }, + "jupyter.command.jupyter.notebookeditor.runfocusedcell.title": "Run Focused Cell", "jupyter.command.jupyter.interruptkernel.title": "Interrupt Kernel", "jupyter.command.jupyter.interruptkernel.shorttitle": "Interrupt", "jupyter.command.jupyter.restartkernel.title": "Restart Kernel", diff --git a/src/commands.ts b/src/commands.ts index 106539fbd8..40192a8f6f 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -58,6 +58,7 @@ export interface ICommandNameArgumentTypeMapping { [DSCommands.RestartKernelAndRunUpToSelectedCell]: [{ notebookEditor: { notebookUri: Uri } } | undefined]; [DSCommands.NotebookEditorRemoveAllCells]: []; [DSCommands.NotebookEditorRunAllCells]: []; + [DSCommands.NotebookEditorRunFocusedCell]: []; [DSCommands.NotebookEditorAddCellBelow]: []; [DSCommands.ExpandAllCells]: []; [DSCommands.CollapseAllCells]: []; diff --git a/src/notebooks/notebookCommandListener.ts b/src/notebooks/notebookCommandListener.ts index 9243c72c18..04907cb1ca 100644 --- a/src/notebooks/notebookCommandListener.ts +++ b/src/notebooks/notebookCommandListener.ts @@ -68,6 +68,9 @@ export class NotebookCommandListener implements INotebookCommandHandler, IExtens this.disposableRegistry.push( commands.registerCommand(Commands.NotebookEditorRunAllCells, () => this.runAllCells()) ); + this.disposableRegistry.push( + commands.registerCommand(Commands.NotebookEditorRunFocusedCell, () => this.runFocusedCell()) + ); this.disposableRegistry.push( commands.registerCommand(Commands.NotebookEditorAddCellBelow, () => this.addCellBelow()) ); @@ -115,6 +118,27 @@ export class NotebookCommandListener implements INotebookCommandHandler, IExtens } } + private runFocusedCell() { + const editor = window.activeNotebookEditor; + if (!editor) { + return; + } + + // Get the first selection range + const range = editor.selections[0]; + if (!range) { + return; + } + + // Execute the cell at the start of the selection + commands + .executeCommand('notebook.cell.execute', { + ranges: [{ start: range.start, end: range.start + 1 }], + document: editor.notebook.uri + }) + .then(noop, noop); + } + private addCellBelow() { if (window.activeNotebookEditor) { commands.executeCommand('notebook.cell.insertCodeCellBelow').then(noop, noop); diff --git a/src/platform/common/constants.ts b/src/platform/common/constants.ts index 9e9cb2b2a5..c6010d716f 100644 --- a/src/platform/common/constants.ts +++ b/src/platform/common/constants.ts @@ -189,6 +189,7 @@ export namespace Commands { export const NotebookEditorRemoveAllCells = 'jupyter.notebookeditor.removeallcells'; export const NotebookEditorRunAllCells = 'jupyter.notebookeditor.runallcells'; export const NotebookEditorRunSelectedCell = 'jupyter.notebookeditor.runselectedcell'; + export const NotebookEditorRunFocusedCell = 'jupyter.notebookeditor.runfocusedcell'; export const NotebookEditorAddCellBelow = 'jupyter.notebookeditor.addcellbelow'; export const ExpandAllCells = 'jupyter.expandallcells'; export const CollapseAllCells = 'jupyter.collapseallcells';