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

Port cell navigation keyboard shortcuts to release #13348

Merged
merged 1 commit into from Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 82 additions & 0 deletions package.json
Expand Up @@ -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": [
Expand Down Expand Up @@ -588,6 +648,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%",
Expand Down Expand Up @@ -1148,6 +1218,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%",
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Expand Up @@ -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": "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",
Expand Down
2 changes: 2 additions & 0 deletions src/client/common/application/commands.ts
Expand Up @@ -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];
Expand Down
10 changes: 10 additions & 0 deletions src/client/datascience/commands/commandRegistry.ts
Expand Up @@ -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);
Expand Down Expand Up @@ -366,6 +368,14 @@ export class CommandRegistry implements IDisposable {
this.getCurrentCodeWatcher()?.changeCellToCode();
}

private async gotoNextCellInFile(): Promise<void> {
this.getCurrentCodeWatcher()?.gotoNextCell();
}

private async gotoPrevCellInFile(): Promise<void> {
this.getCurrentCodeWatcher()?.gotoPreviousCell();
}

private async runAllCellsAboveFromCursor(): Promise<void> {
const currentCodeLens = this.getCurrentCodeLens();
if (currentCodeLens) {
Expand Down
4 changes: 4 additions & 0 deletions src/client/datascience/constants.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
46 changes: 46 additions & 0 deletions src/client/datascience/editor-integration/codewatcher.ts
Expand Up @@ -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);
Expand Down Expand Up @@ -1053,6 +1087,18 @@ 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 && i < currentIndex && i + 1 === currentIndex
);
}
return undefined;
}

private async runFileInteractiveInternal(debug: boolean) {
if (this.document) {
const code = this.document.getText();
Expand Down
2 changes: 2 additions & 0 deletions src/client/datascience/types.ts
Expand Up @@ -679,6 +679,8 @@ export interface ICodeWatcher {
changeCellToMarkdown(): void;
changeCellToCode(): void;
debugCurrentCell(): Promise<void>;
gotoNextCell(): void;
gotoPreviousCell(): void;
}

export const ICodeLensFactory = Symbol('ICodeLensFactory');
Expand Down
2 changes: 2 additions & 0 deletions src/client/telemetry/index.ts
Expand Up @@ -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
*/
Expand Down