Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribute shift+enter, ctrl+enter, L, shift+L #6205

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/4438.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In preview native notebooks UI, contribute `L` keybinding to toggle line numbers for the current cell, and `shift+L` keybinding to toggle line numbers for all cells.
1 change: 1 addition & 0 deletions news/1 Enhancements/5976.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When editing a markdown cell in preview native notebooks UI, contribute `ctrl+enter` keybinding to render current markdown cell, and `shift+enter` to render current markdown cell and skip to the next cell.
1 change: 1 addition & 0 deletions news/1 Enhancements/6037.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contribute extension-level `shift+enter` keybinding to execute current code cell and select below in preview native notebooks UI.
75 changes: 36 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,105 +98,77 @@
"when": "editorTextFocus && !editorHasSelection && jupyter.hascodecells && !notebookEditorFocused"
},
{
"mac": "F",
"win": "F",
"linux": "F",
"key": "F",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.find"
},
{
"mac": "K",
"win": "K",
"linux": "K",
"key": "K",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "list.focusUp"
},
{
"mac": "J",
"win": "J",
"linux": "J",
"key": "J",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "list.focusDown"
},
{
"mac": "A",
"win": "A",
"linux": "A",
"key": "A",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.insertCodeCellAbove"
},
{
"mac": "B",
"win": "B",
"linux": "B",
"key": "B",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.insertCodeCellBelow"
},
{
"mac": "D D",
"win": "D D",
"linux": "D D",
"key": "D D",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.delete"
},
{
"mac": "Z",
"win": "Z",
"linux": "Z",
"key": "Z",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "jupyter.notebookeditor.keybind.undo"
},
{
"mac": "S",
"win": "S",
"linux": "S",
"key": "S",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "jupyter.notebookeditor.keybind.save"
},
{
"mac": "C",
"win": "C",
"linux": "C",
"key": "C",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.copy"
},
{
"mac": "X",
"win": "X",
"linux": "X",
"key": "X",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.cut"
},
{
"mac": "V",
"win": "V",
"linux": "V",
"key": "V",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.paste"
},
{
"mac": "O",
"win": "O",
"linux": "O",
"key": "O",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "jupyter.notebookeditor.keybind.toggleOutput"
},
{
"mac": "ctrl+shift+-",
"win": "ctrl+shift+-",
"linux": "ctrl+shift+-",
"key": "shift+L",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.toggleLineNumbers"
},
{
"key": "L",
"when": "notebookEditorFocused && !inputFocus && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.toggleLineNumbers"
},
{
"key": "ctrl+shift+-",
"when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.split"
},
Expand All @@ -205,6 +177,21 @@
"when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts",
"command": "notebook.cell.execute"
},
{
"key": "ctrl+enter",
"when": "inputFocus && notebookEditorFocused && !editorHasMultipleSelections && !editorHasSelection && !editorHoverVisible && notebookCellType == 'markup'",
"command": "notebook.cell.quitEdit"
},
{
"key": "shift+enter",
"when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookType == jupyter-notebook && config.jupyter.enableKeyboardShortcuts || notebookCellListFocused && notebookCellType == 'markup' || notebookCellListFocused && notebookCellType == 'code' && notebookCellExecutionState == 'failed' || notebookCellExecutionState == 'idle' || notebookCellExecutionState == 'succeeded' && notebookKernelCount > 0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This when statement strikes me as a bit gnarly to parse. But not sure if we can to anything to change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a merge of the when clauses for our existing ctrl+enter keybinding and VS Code's shift+enter keybinding.

"command": "notebook.cell.executeAndSelectBelow"
},
{
"key": "shift+enter",
"when": "inputFocus && notebookEditorFocused && !editorHasMultipleSelections && !editorHasSelection && !editorHoverVisible && notebookCellType == 'markup'",
"command": "jupyter.notebookeditor.keybind.renderMarkdownAndSelectBelow"
},
{
"command": "jupyter.insertCellBelowPosition",
"key": "ctrl+; s",
Expand Down Expand Up @@ -385,6 +372,11 @@
"title": "%DataScience.toggleCellOutput%",
"category": "Notebook"
},
{
"command": "jupyter.notebookeditor.keybind.renderMarkdownAndSelectBelow",
"title": "%DataScience.renderMarkdownAndSelectBelow%",
"category": "Notebook"
},
{
"command": "jupyter.selectCell",
"title": "%jupyter.command.jupyter.selectCell.title%",
Expand Down Expand Up @@ -894,6 +886,11 @@
"title": "%DataScience.toggleCellOutput%",
"when": "notebookType == jupyter-notebook"
},
{
"command": "jupyter.notebookeditor.keybind.renderMarkdownAndSelectBelow",
"title": "%DataScience.renderMarkdownAndSelectBelow%",
"when": "false"
},
{
"command": "jupyter.exportAsPythonScript",
"title": "%jupyter.command.jupyter.exportAsPythonScript.title%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
"DataScience.addCell": "Add cell",
"DataScience.runAll": "Run all cells",
"DataScience.toggleCellOutput": "Toggle Cell Output",
"DataScience.renderMarkdownAndSelectBelow": "Execute Notebook Cell and Select Below",
"DataScience.convertingToPythonFile": "Converting ipynb to python file",
"DataScience.untitledNotebookMessage": "Your changes will be lost if you don't save them.",
"DataScience.untitledNotebookYes": "Save",
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 @@ -53,6 +53,9 @@ interface ICommandNameWithoutArgumentTypeMapping {
[DSCommands.ResetLoggingLevel]: [];
[DSCommands.OpenVariableView]: [];
[DSCommands.NotebookEditorToggleOutput]: [];
[DSCommands.NotebookEditorKeybindRenderMarkdownAndSelectBelow]: [];
['notebook.cell.quitEdit']: [];
['notebook.cell.executeAndSelectBelow']: [];
['notebook.cell.collapseCellOutput']: [];
['notebook.cell.expandCellOutput']: [];
}
Expand Down
13 changes: 12 additions & 1 deletion src/client/datascience/commands/notebookCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export class NotebookCommands implements IDisposable {
this.commandManager.registerCommand(Commands.NotebookEditorExpandAllCells, this.expandAll, this),
this.commandManager.registerCommand(Commands.NotebookEditorKeybindSave, this.keybindSave, this),
this.commandManager.registerCommand(Commands.NotebookEditorKeybindUndo, this.keybindUndo, this),
this.commandManager.registerCommand(Commands.NotebookEditorToggleOutput, this.toggleOutput, this)
this.commandManager.registerCommand(Commands.NotebookEditorToggleOutput, this.toggleOutput, this),
this.commandManager.registerCommand(
Commands.NotebookEditorKeybindRenderMarkdownAndSelectBelow,
this.renderMarkdownAndSelectBelow,
this
)
);
}
public dispose() {
Expand All @@ -51,6 +56,12 @@ export class NotebookCommands implements IDisposable {
}
}

private renderMarkdownAndSelectBelow() {
this.commandManager
.executeCommand('notebook.cell.quitEdit')
.then(() => this.commandManager.executeCommand('notebook.cell.executeAndSelectBelow'));
}

private collapseAll() {
if (this.notebookEditorProvider.activeEditor) {
this.notebookEditorProvider.activeEditor.collapseAllCells();
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 @@ -161,6 +161,8 @@ export namespace Commands {
export const OpenVariableView = 'jupyter.openVariableView';
export const NotebookEditorKeybindSave = 'jupyter.notebookeditor.keybind.save';
export const NotebookEditorKeybindUndo = 'jupyter.notebookeditor.keybind.undo';
export const NotebookEditorKeybindRenderMarkdownAndSelectBelow =
'jupyter.notebookeditor.keybind.renderMarkdownAndSelectBelow';
export const NotebookEditorToggleOutput = 'jupyter.notebookeditor.keybind.toggleOutput';
}

Expand Down