From d928e3b68fbcc1da6078966cc110c99fcd08ee44 Mon Sep 17 00:00:00 2001 From: greazer Date: Thu, 6 Aug 2020 16:21:57 -0700 Subject: [PATCH 1/5] Add Goto Prev/Next Cell --- .vscode/settings.json | 3 +- package.json | 22 ++++++++ package.nls.json | 2 + src/client/common/application/commands.ts | 2 + .../datascience/commands/commandRegistry.ts | 10 ++++ src/client/datascience/constants.ts | 4 ++ .../editor-integration/codewatcher.ts | 50 +++++++++++++++++++ src/client/datascience/types.ts | 2 + src/client/telemetry/index.ts | 2 + 9 files changed, 96 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b2dc13efe26e..bc86d1d19e88 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -56,5 +56,6 @@ "--max-line-length=88" ], "typescript.preferences.importModuleSpecifier": "relative", - "debug.javascript.usePreview": false + "debug.javascript.usePreview": false, + "python.pythonPath": "C:\\Users\\jimg\\anaconda3\\python.exe" } diff --git a/package.json b/package.json index c1f396276dd7..609e6936a9a5 100644 --- a/package.json +++ b/package.json @@ -588,6 +588,16 @@ "title": "%python.command.python.datascience.changeCellToCode.title%", "category": "Python" }, + { + "command": "python.datascience.gotoNextCellInFile", + "title": "%python.command.python.datascience.gotoNextCellInFile.title%", + "category": "Python" + }, + { + "command": "python.datascience.gotoPrevCellInFile", + "title": "%python.command.python.datascience.gotoPrevCellInFile.title%", + "category": "Python" + }, { "command": "python.datascience.runcurrentcelladvance", "title": "%python.command.python.datascience.runcurrentcelladvance.title%", @@ -1148,6 +1158,18 @@ "category": "Python", "when": "python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" }, + { + "command": "python.datascience.gotoNextCellInFile", + "title": "%python.command.python.datascience.gotoNextCellInFile.title%", + "category": "Python", + "when": "python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.gotoPrevCellInFile", + "title": "%python.command.python.datascience.gotoPrevCellInFile.title%", + "category": "Python", + "when": "python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, { "command": "python.datascience.runcurrentcell", "title": "%python.command.python.datascience.runcurrentcell.title%", diff --git a/package.nls.json b/package.nls.json index f5042baf1ed6..f0f0bd1fd767 100644 --- a/package.nls.json +++ b/package.nls.json @@ -85,6 +85,8 @@ "python.command.python.datascience.moveCellsDown.title": "Move Selected Cells Down", "python.command.python.datascience.changeCellToMarkdown.title": "Change Cell to Markdown", "python.command.python.datascience.changeCellToCode.title": "Change Cell to Code", + "python.command.python.datascience.gotoNextCellInFile.title": "Goto Next Cell", + "python.command.python.datascience.gotoPrevCellInFile.title": "Goto Previous Cell", "python.command.python.datascience.showhistorypane.title": "Show Python Interactive Window", "python.command.python.datascience.createnewinteractive.title": "Create Python Interactive Window", "python.command.python.datascience.selectjupyteruri.title": "Specify local or remote Jupyter server for connections", diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index 3ef4263c8670..880dbc5599f3 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -184,6 +184,8 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu [DSCommands.MoveCellsDown]: []; [DSCommands.ChangeCellToMarkdown]: []; [DSCommands.ChangeCellToCode]: []; + [DSCommands.GotoNextCellInFile]: []; + [DSCommands.GotoPrevCellInFile]: []; [DSCommands.ScrollToCell]: [Uri, string]; [DSCommands.ViewJupyterOutput]: []; [DSCommands.ExportAsPythonScript]: [INotebookModel]; diff --git a/src/client/datascience/commands/commandRegistry.ts b/src/client/datascience/commands/commandRegistry.ts index 61f1cc8b73d3..ff9c64025dd8 100644 --- a/src/client/datascience/commands/commandRegistry.ts +++ b/src/client/datascience/commands/commandRegistry.ts @@ -77,6 +77,8 @@ export class CommandRegistry implements IDisposable { this.registerCommand(Commands.MoveCellsDown, this.moveCellsDown); this.registerCommand(Commands.ChangeCellToMarkdown, this.changeCellToMarkdown); this.registerCommand(Commands.ChangeCellToCode, this.changeCellToCode); + this.registerCommand(Commands.GotoNextCellInFile, this.gotoNextCellInFile); + this.registerCommand(Commands.GotoPrevCellInFile, this.gotoPrevCellInFile); this.registerCommand(Commands.RunAllCellsAbovePalette, this.runAllCellsAboveFromCursor); this.registerCommand(Commands.RunCellAndAllBelowPalette, this.runCellAndAllBelowFromCursor); this.registerCommand(Commands.RunToLine, this.runToLine); @@ -366,6 +368,14 @@ export class CommandRegistry implements IDisposable { this.getCurrentCodeWatcher()?.changeCellToCode(); } + private async gotoNextCellInFile(): Promise { + this.getCurrentCodeWatcher()?.gotoNextCell(); + } + + private async gotoPrevCellInFile(): Promise { + this.getCurrentCodeWatcher()?.gotoPreviousCell(); + } + private async runAllCellsAboveFromCursor(): Promise { const currentCodeLens = this.getCurrentCodeLens(); if (currentCodeLens) { diff --git a/src/client/datascience/constants.ts b/src/client/datascience/constants.ts index 3a4bebfd6dda..8f7ec1ef4c08 100644 --- a/src/client/datascience/constants.ts +++ b/src/client/datascience/constants.ts @@ -92,6 +92,8 @@ export namespace Commands { export const MoveCellsDown = 'python.datascience.moveCellsDown'; export const ChangeCellToMarkdown = 'python.datascience.changeCellToMarkdown'; export const ChangeCellToCode = 'python.datascience.changeCellToCode'; + export const GotoNextCellInFile = 'python.datascience.gotoNextCellInFile'; + export const GotoPrevCellInFile = 'python.datascience.gotoPrevCellInFile'; export const ScrollToCell = 'python.datascience.scrolltocell'; export const CreateNewNotebook = 'python.datascience.createnewnotebook'; export const ViewJupyterOutput = 'python.datascience.viewJupyterOutput'; @@ -189,6 +191,8 @@ export enum Telemetry { MoveCellsDown = 'DATASCIENCE.RUN_MOVE_CELLS_DOWN', ChangeCellToMarkdown = 'DATASCIENCE.RUN_CHANGE_CELL_TO_MARKDOWN', ChangeCellToCode = 'DATASCIENCE.RUN_CHANGE_CELL_TO_CODE', + GotoNextCellInFile = 'DATASCIENCE.GOTO_NEXT_CELL_IN_FILE', + GotoPrevCellInFile = 'DATASCIENCE.GOTO_PREV_CELL_IN_FILE', RunSelectionOrLine = 'DATASCIENCE.RUN_SELECTION_OR_LINE', RunToLine = 'DATASCIENCE.RUN_TO_LINE', RunFromLine = 'DATASCIENCE.RUN_FROM_LINE', diff --git a/src/client/datascience/editor-integration/codewatcher.ts b/src/client/datascience/editor-integration/codewatcher.ts index 856108875330..8a593ea6181f 100644 --- a/src/client/datascience/editor-integration/codewatcher.ts +++ b/src/client/datascience/editor-integration/codewatcher.ts @@ -654,6 +654,40 @@ export class CodeWatcher implements ICodeWatcher { }); } + @captureTelemetry(Telemetry.GotoNextCellInFile) + public gotoNextCell() { + const editor = this.documentManager.activeTextEditor; + if (!editor || !editor.selection) { + return; + } + + const currentSelection = editor.selection; + + const currentRunCellLens = this.getCurrentCellLens(currentSelection.start); + const nextRunCellLens = this.getNextCellLens(currentSelection.start); + + if (currentRunCellLens && nextRunCellLens) { + this.advanceToRange(nextRunCellLens.range); + } + } + + @captureTelemetry(Telemetry.GotoPrevCellInFile) + public gotoPreviousCell() { + const editor = this.documentManager.activeTextEditor; + if (!editor || !editor.selection) { + return; + } + + const currentSelection = editor.selection; + + const currentRunCellLens = this.getCurrentCellLens(currentSelection.start); + const prevRunCellLens = this.getPreviousCellLens(currentSelection.start); + + if (currentRunCellLens && prevRunCellLens) { + this.advanceToRange(prevRunCellLens.range); + } + } + private applyToCells(callback: (editor: TextEditor, cell: ICellRange, cellIndex: number) => void) { const editor = this.documentManager.activeTextEditor; const startEndCellIndex = this.getStartEndCellIndex(editor?.selection); @@ -1053,6 +1087,22 @@ export class CodeWatcher implements ICodeWatcher { return undefined; } + private getPreviousCellLens(pos: Position): CodeLens | undefined { + const currentIndex = this.codeLenses.findIndex( + (l) => l.range.contains(pos) && l.command !== undefined && l.command.command === Commands.RunCell + ); + if (currentIndex >= 1) { + return this.codeLenses.find( + (l: CodeLens, i: number) => + l.command !== undefined && + l.command.command === Commands.RunCell && + i < currentIndex && + i + 2 === currentIndex + ); + } + return undefined; + } + private async runFileInteractiveInternal(debug: boolean) { if (this.document) { const code = this.document.getText(); diff --git a/src/client/datascience/types.ts b/src/client/datascience/types.ts index 2af5d4030f38..ffd7bcc1abca 100644 --- a/src/client/datascience/types.ts +++ b/src/client/datascience/types.ts @@ -679,6 +679,8 @@ export interface ICodeWatcher { changeCellToMarkdown(): void; changeCellToCode(): void; debugCurrentCell(): Promise; + gotoNextCell(): void; + gotoPreviousCell(): void; } export const ICodeLensFactory = Symbol('ICodeLensFactory'); diff --git a/src/client/telemetry/index.ts b/src/client/telemetry/index.ts index a8f973bca77f..74c0046580cd 100644 --- a/src/client/telemetry/index.ts +++ b/src/client/telemetry/index.ts @@ -1747,6 +1747,8 @@ export interface IEventNamePropertyMapping { [Telemetry.MoveCellsDown]: never | undefined; [Telemetry.ChangeCellToMarkdown]: never | undefined; [Telemetry.ChangeCellToCode]: never | undefined; + [Telemetry.GotoNextCellInFile]: never | undefined; + [Telemetry.GotoPrevCellInFile]: never | undefined; /** * Misc */ From 2b3081407849bd620889866ba41d5b59d26f7e0f Mon Sep 17 00:00:00 2001 From: Jim Griesmer Date: Thu, 6 Aug 2020 16:54:22 -0700 Subject: [PATCH 2/5] Add goto previous cell --- src/client/datascience/editor-integration/codewatcher.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/client/datascience/editor-integration/codewatcher.ts b/src/client/datascience/editor-integration/codewatcher.ts index 8a593ea6181f..7c10f3e61749 100644 --- a/src/client/datascience/editor-integration/codewatcher.ts +++ b/src/client/datascience/editor-integration/codewatcher.ts @@ -1093,11 +1093,7 @@ export class CodeWatcher implements ICodeWatcher { ); if (currentIndex >= 1) { return this.codeLenses.find( - (l: CodeLens, i: number) => - l.command !== undefined && - l.command.command === Commands.RunCell && - i < currentIndex && - i + 2 === currentIndex + (l: CodeLens, i: number) => l.command !== undefined && i < currentIndex && i + 1 === currentIndex ); } return undefined; From fd526f3e5a5afb205fea6f5087bcc05a3458d18f Mon Sep 17 00:00:00 2001 From: Jim Griesmer Date: Thu, 6 Aug 2020 17:54:35 -0700 Subject: [PATCH 3/5] Remove unneeded changes --- .vscode/settings.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bc86d1d19e88..b2dc13efe26e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -56,6 +56,5 @@ "--max-line-length=88" ], "typescript.preferences.importModuleSpecifier": "relative", - "debug.javascript.usePreview": false, - "python.pythonPath": "C:\\Users\\jimg\\anaconda3\\python.exe" + "debug.javascript.usePreview": false } From 5dcf4e49ded986cb87485e4b0772c6b14941bed4 Mon Sep 17 00:00:00 2001 From: Jim Griesmer Date: Thu, 6 Aug 2020 23:41:31 -0700 Subject: [PATCH 4/5] Add default keybindings for cell commands --- package.json | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/package.json b/package.json index 609e6936a9a5..0318fac9aa85 100644 --- a/package.json +++ b/package.json @@ -229,6 +229,66 @@ "linux": "ctrl+shift+-", "when": "editorTextFocus && inputFocus && notebookEditorFocused && notebookViewType == jupyter-notebook", "command": "notebook.cell.split" + }, + { + "command": "python.datascience.insertCellBelowPosition", + "key": "ctrl+; s", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.insertCellBelow", + "key": "ctrl+; b", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.insertCellAbove", + "key": "ctrl+; a", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.deleteCells", + "key": "ctrl+; x", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.extendSelectionByCellAbove", + "key": "ctrl+alt+shift+[", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.extendSelectionByCellBelow", + "key": "ctrl+alt+shift+]", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.moveCellsUp", + "key": "ctrl+; u", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.moveCellsDown", + "key": "ctrl+; d", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.changeCellToMarkdown", + "key": "ctrl+; m", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.changeCellToCode", + "key": "ctrl+; c", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.gotoNextCellInFile", + "key": "ctrl+alt+]", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" + }, + { + "command": "python.datascience.gotoPrevCellInFile", + "key": "ctrl+alt+[", + "when": "editorTextFocus && python.datascience.hascodecells && python.datascience.featureenabled && !notebookEditorFocused" } ], "commands": [ From df8ab95722cf0620482d7b95ff3820213f4ff5dc Mon Sep 17 00:00:00 2001 From: Jim Griesmer Date: Thu, 6 Aug 2020 23:46:34 -0700 Subject: [PATCH 5/5] Goto should be Go to --- package.nls.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.nls.json b/package.nls.json index f0f0bd1fd767..53bb5b2a73d0 100644 --- a/package.nls.json +++ b/package.nls.json @@ -85,8 +85,8 @@ "python.command.python.datascience.moveCellsDown.title": "Move Selected Cells Down", "python.command.python.datascience.changeCellToMarkdown.title": "Change Cell to Markdown", "python.command.python.datascience.changeCellToCode.title": "Change Cell to Code", - "python.command.python.datascience.gotoNextCellInFile.title": "Goto Next Cell", - "python.command.python.datascience.gotoPrevCellInFile.title": "Goto Previous Cell", + "python.command.python.datascience.gotoNextCellInFile.title": "Go to Next Cell", + "python.command.python.datascience.gotoPrevCellInFile.title": "Go to Previous Cell", "python.command.python.datascience.showhistorypane.title": "Show Python Interactive Window", "python.command.python.datascience.createnewinteractive.title": "Create Python Interactive Window", "python.command.python.datascience.selectjupyteruri.title": "Specify local or remote Jupyter server for connections",