Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Lourens <roblourens@gmail.com>2022-05-11 01:11:01 +0300
committerRob Lourens <roblourens@gmail.com>2022-05-11 02:06:18 +0300
commitf01851dcdca4e532447d0481dc58cc0ae151ba4c (patch)
treea4092d0477f41478ee6532b9efffce32427821f0
parent8965a0211494f0ec658c628bab407c1c8555e028 (diff)
Set correct editor selection when moving cursor from one cell editor to another. Fixes #147527
-rw-r--r--src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.ts8
-rw-r--r--src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts1
-rw-r--r--src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts24
3 files changed, 24 insertions, 9 deletions
diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.ts b/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.ts
index 763c427e321..b1251dfd3cc 100644
--- a/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.ts
+++ b/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.ts
@@ -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,
@@ -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,
@@ -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;
}
});
diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
index 77a50b8c655..6065c4cc781 100644
--- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
+++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
@@ -122,6 +122,7 @@ export interface ICommonCellInfo {
export interface IFocusNotebookCellOptions {
readonly skipReveal?: boolean;
+ readonly focusEditorLine?: number;
}
//#endregion
diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts
index 9810b6e6a38..906b6c73fef 100644
--- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts
+++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts
@@ -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);