From 8edb01da0ddeb00b6497cb92c8551fec5adba95e Mon Sep 17 00:00:00 2001 From: jankuca Date: Tue, 21 Oct 2025 14:57:00 +0200 Subject: [PATCH 1/4] feat: add cmd+enter command for running focused block --- package.json | 14 ++++++++++++++ src/commands.ts | 1 + src/notebooks/notebookCommandListener.ts | 24 ++++++++++++++++++++++++ src/platform/common/constants.ts | 1 + 4 files changed, 40 insertions(+) diff --git a/package.json b/package.json index 575cc95d56..33d3887ea6 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": [ @@ -478,6 +486,12 @@ "category": "Notebook", "enablement": "!jupyter.webExtension" }, + { + "command": "jupyter.notebookeditor.runfocusedcell", + "title": "Run Focused Cell", + "category": "Notebook", + "enablement": "notebookEditorFocused" + }, { "command": "jupyter.expandallcells", "title": "%jupyter.command.jupyter.expandallcells.title%", diff --git a/src/commands.ts b/src/commands.ts index eaf0b65930..e4ccedd4c9 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 33c0dac054..00d668bc66 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'; From 4e5470bbcbfedfaf25a88695fab5e844dd350345 Mon Sep 17 00:00:00 2001 From: jankuca Date: Wed, 22 Oct 2025 16:26:19 +0200 Subject: [PATCH 2/4] remove unneccessary command override --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 33d3887ea6..690f46f0ab 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,6 @@ }, { "key": "cmd+enter", - "mac": "cmd+enter", "win": "ctrl+enter", "linux": "ctrl+enter", "when": "notebookEditorFocused && !findInputFocussed && !replaceInputFocussed", From 0d99c0d866f33f57128463968448ba982f961021 Mon Sep 17 00:00:00 2001 From: jankuca Date: Wed, 22 Oct 2025 16:27:55 +0200 Subject: [PATCH 3/4] localize run command label --- package.json | 2 +- package.nls.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 690f46f0ab..83bf4f585a 100644 --- a/package.json +++ b/package.json @@ -487,7 +487,7 @@ }, { "command": "jupyter.notebookeditor.runfocusedcell", - "title": "Run Focused Cell", + "title": "%jupyter.command.jupyter.notebookeditor.runfocusedcell.title%", "category": "Notebook", "enablement": "notebookEditorFocused" }, diff --git a/package.nls.json b/package.nls.json index f323d4cfec..fddc2e8856 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", From 3e3bc9da22b14183a825c0fe0908dd78fa3cbf1a Mon Sep 17 00:00:00 2001 From: jankuca Date: Thu, 23 Oct 2025 10:48:42 +0200 Subject: [PATCH 4/4] Revert "remove unneccessary command override" This reverts commit 4e5470bbcbfedfaf25a88695fab5e844dd350345. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b0329af587..253598f99d 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ }, { "key": "cmd+enter", + "mac": "cmd+enter", "win": "ctrl+enter", "linux": "ctrl+enter", "when": "notebookEditorFocused && !findInputFocussed && !replaceInputFocussed",