Skip to content

Commit

Permalink
Set correct editor selection when moving cursor from one cell editor …
Browse files Browse the repository at this point in the history
…to another. Fixes #147527
  • Loading branch information
roblourens committed May 10, 2022
1 parent 8965a02 commit f01851d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const NOTEBOOK_CURSOR_PAGEDOWN_COMMAND_ID = 'notebook.cell.cursorPageDown';
const NOTEBOOK_CURSOR_PAGEDOWN_SELECT_COMMAND_ID = 'notebook.cell.cursorPageDownSelect';


registerAction2(class extends NotebookCellAction {
registerAction2(class FocusNextCellAction extends NotebookCellAction {
constructor() {
super({
id: NOTEBOOK_FOCUS_NEXT_EDITOR,
Expand Down Expand Up @@ -76,13 +76,13 @@ registerAction2(class extends NotebookCellAction {

const newCell = editor.cellAt(idx + 1);
const newFocusMode = newCell.cellKind === CellKind.Markup && newCell.getEditState() === CellEditState.Preview ? 'container' : 'editor';
editor.focusNotebookCell(newCell, newFocusMode);
editor.focusNotebookCell(newCell, newFocusMode, { focusEditorLine: 1 });
editor.cursorNavigationMode = true;
}
});


registerAction2(class extends NotebookCellAction {
registerAction2(class FocusPreviousCellAction extends NotebookCellAction {
constructor() {
super({
id: NOTEBOOK_FOCUS_PREVIOUS_EDITOR,
Expand Down Expand Up @@ -118,7 +118,7 @@ registerAction2(class extends NotebookCellAction {

const newCell = editor.cellAt(idx - 1);
const newFocusMode = newCell.cellKind === CellKind.Markup && newCell.getEditState() === CellEditState.Preview ? 'container' : 'editor';
editor.focusNotebookCell(newCell, newFocusMode);
editor.focusNotebookCell(newCell, newFocusMode, { focusEditorLine: -1 });
editor.cursorNavigationMode = true;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export interface ICommonCellInfo {

export interface IFocusNotebookCellOptions {
readonly skipReveal?: boolean;
readonly focusEditorLine?: number;
}

//#endregion
Expand Down
24 changes: 19 additions & 5 deletions src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2329,13 +2329,27 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
cell.updateEditState(CellEditState.Editing, 'focusNotebookCell');
cell.focusMode = CellFocusMode.Editor;
if (!options?.skipReveal) {
const selectionsStartPosition = cell.getSelectionsStartPosition();
if (selectionsStartPosition?.length) {
const firstSelectionPosition = selectionsStartPosition[0];
this.revealRangeInCenterIfOutsideViewportAsync(cell, Range.fromPositions(firstSelectionPosition, firstSelectionPosition));
if (typeof options?.focusEditorLine === 'number') {
this.revealLineInViewAsync(cell, options.focusEditorLine).then(() => {
const editor = this._renderedEditors.get(cell)!;
const focusEditorLine = options.focusEditorLine === -1 && editor.hasModel() ? editor.getModel()?.getLineCount() : options.focusEditorLine!;
editor?.setSelection({
startLineNumber: focusEditorLine,
startColumn: 1,
endLineNumber: focusEditorLine,
endColumn: 1
});
});
} else {
this.revealInCenterIfOutsideViewport(cell);
const selectionsStartPosition = cell.getSelectionsStartPosition();
if (selectionsStartPosition?.length) {
const firstSelectionPosition = selectionsStartPosition[0];
this.revealRangeInCenterIfOutsideViewportAsync(cell, Range.fromPositions(firstSelectionPosition, firstSelectionPosition));
} else {
this.revealInCenterIfOutsideViewport(cell);
}
}

}
} else if (focusItem === 'output') {
this.focusElement(cell);
Expand Down

0 comments on commit f01851d

Please sign in to comment.