Skip to content

Commit

Permalink
PORT - Fix for top level save and undo commands (#4851)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanMatthewHuff authored Feb 17, 2021
1 parent 23b6e91 commit e7ce3f2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
([#4730](https://github.com/Microsoft/vscode-jupyter/issues/4730))
1. Add survey for the new Notebooks experience experiment.
([#4726](https://github.com/microsoft/vscode-jupyter/issues/4726))
1. Don't overwrite the top level VS Code Save and Undo command keybindings.
([#4527](https://github.com/Microsoft/vscode-jupyter/issues/4527))

### Fixes

Expand Down
28 changes: 26 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@
"linux": "Z",
"key": "Z",
"when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "undo"
"command": "jupyter.notebookeditor.keybind.undo"
},
{
"mac": "S",
"win": "S",
"linux": "S",
"key": "S",
"when": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "workbench.action.files.save"
"command": "jupyter.notebookeditor.keybind.save"
},
{
"mac": "C",
Expand Down Expand Up @@ -576,6 +576,18 @@
"title": "%jupyter.command.jupyter.redocells.title%",
"category": "Notebook"
},
{
"command": "jupyter.notebookeditor.keybind.undo",
"title": "%jupyter.command.jupyter.notebookeditor.keybind.undo.title%",
"category": "Notebook",
"enablement": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts"
},
{
"command": "jupyter.notebookeditor.keybind.save",
"title": "%jupyter.command.jupyter.notebookeditor.keybind.save.title%",
"category": "Notebook",
"enablement": "notebookEditorFocused && !inputFocus && notebookViewType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts"
},
{
"command": "jupyter.removeallcells",
"title": "%jupyter.command.jupyter.removeallcells.title%",
Expand Down Expand Up @@ -1165,6 +1177,18 @@
"category": "Notebook",
"when": "notebookEditorFocused"
},
{
"command": "jupyter.notebookeditor.keybind.undo",
"title": "%jupyter.command.jupyter.notebookeditor.keybind.undo.title%",
"category": "Notebook",
"when": "false"
},
{
"command": "jupyter.notebookeditor.keybind.save",
"title": "%jupyter.command.jupyter.notebookeditor.keybind.save.title%",
"category": "Notebook",
"when": "false"
},
{
"command": "jupyter.expandallcells",
"title": "%jupyter.command.jupyter.expandallcells.title%",
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
"jupyter.command.jupyter.removeallcells.title": "Delete All Interactive Cells",
"jupyter.command.jupyter.notebookeditor.removeallcells.title": "Delete All Notebook Editor Cells",
"jupyter.command.jupyter.notebookeditor.addcellbelow.title": "Add Empty Cell to Notebook File",
"jupyter.command.jupyter.notebookeditor.keybind.undo.title": "Undo",
"jupyter.command.jupyter.notebookeditor.keybind.save.title": "Save",
"jupyter.command.jupyter.interruptkernel.title": "Interrupt Jupyter Kernel",
"jupyter.command.jupyter.restartkernel.title": "Restart Jupyter Kernel",
"jupyter.command.jupyter.expandallcells.title": "Expand All Interactive Cells",
Expand Down
3 changes: 3 additions & 0 deletions src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
['vscode.open']: [Uri];
['workbench.action.files.saveAs']: [Uri];
['workbench.action.files.save']: [Uri];
['undo']: [];
[DSCommands.ExportFileAndOutputAsNotebook]: [Uri];
[DSCommands.RunAllCells]: [Uri];
[DSCommands.RunCell]: [Uri, number, number, number, number];
Expand Down Expand Up @@ -151,4 +152,6 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
[DSCommands.ClearSavedJupyterUris]: [];
[DSCommands.SelectJupyterURI]: [undefined, 'toolbar' | 'nativeNotebookStatusBar' | undefined];
[DSCommands.SelectNativeJupyterUriFromToolBar]: [];
[DSCommands.NotebookEditorKeybindSave]: [];
[DSCommands.NotebookEditorKeybindUndo]: [];
}
17 changes: 16 additions & 1 deletion src/client/datascience/commands/notebookCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class NotebookCommands implements IDisposable {
this.commandManager.registerCommand(Commands.SwitchJupyterKernel, this.switchKernel, this),
this.commandManager.registerCommand(Commands.SetJupyterKernel, this.setKernel, this),
this.commandManager.registerCommand(Commands.NotebookEditorCollapseAllCells, this.collapseAll, this),
this.commandManager.registerCommand(Commands.NotebookEditorExpandAllCells, this.expandAll, this)
this.commandManager.registerCommand(Commands.NotebookEditorExpandAllCells, this.expandAll, this),
this.commandManager.registerCommand(Commands.NotebookEditorKeybindSave, this.keybindSave, this),
this.commandManager.registerCommand(Commands.NotebookEditorKeybindUndo, this.keybindUndo, this)
);
}
public dispose() {
Expand All @@ -52,6 +54,19 @@ export class NotebookCommands implements IDisposable {
}
}

private keybindSave() {
if (this.notebookEditorProvider.activeEditor) {
void this.commandManager.executeCommand(
'workbench.action.files.save',
this.notebookEditorProvider.activeEditor.file
);
}
}

private keybindUndo() {
void this.commandManager.executeCommand('undo');
}

private async switchKernel(options: ISwitchKernelOptions | undefined) {
// If no identity, spec, or resource, look at the active editor or interactive window.
// Only one is possible to be active at any point in time
Expand Down
2 changes: 2 additions & 0 deletions src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export namespace Commands {
export const ShowDataViewer = 'jupyter.showDataViewer';
export const ClearSavedJupyterUris = 'jupyter.clearSavedJupyterUris';
export const OpenVariableView = 'jupyter.openVariableView';
export const NotebookEditorKeybindSave = 'jupyter.notebookeditor.keybind.save';
export const NotebookEditorKeybindUndo = 'jupyter.notebookeditor.keybind.undo';
}

export namespace CodeLensCommands {
Expand Down

0 comments on commit e7ce3f2

Please sign in to comment.