remove nbvm.setSelections.

This commit is contained in:
rebornix 2021-06-11 14:52:34 -07:00
parent 3086bb5956
commit 5e75d958ec
8 changed files with 83 additions and 34 deletions

View file

@ -282,7 +282,8 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 0, end: 1 }, [{ start: 0, end: 1 }]);
editor.setFocus({ start: 0, end: 1 });
editor.setSelections([{ start: 0, end: 1 }]);
runDeleteAction(viewModel, viewModel.cellAt(0)!);
assert.strictEqual(viewModel.length, 2);
});
@ -297,7 +298,8 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 0, end: 1 }, [{ start: 0, end: 2 }]);
editor.setFocus({ start: 0, end: 1 });
editor.setSelections([{ start: 0, end: 2 }]);
runDeleteAction(viewModel, viewModel.cellAt(0)!);
assert.strictEqual(viewModel.length, 1);
});
@ -313,7 +315,8 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 0, end: 1 }, [{ start: 2, end: 4 }]);
editor.setFocus({ start: 0, end: 1 });
editor.setSelections([{ start: 2, end: 4 }]);
runDeleteAction(viewModel, viewModel.cellAt(0)!);
assert.strictEqual(viewModel.length, 3);
});
@ -328,7 +331,8 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 0, end: 1 }, [{ start: 0, end: 1 }]);
editor.setFocus({ start: 0, end: 1 });
editor.setSelections([{ start: 0, end: 1 }]);
runDeleteAction(viewModel, viewModel.cellAt(2)!);
assert.strictEqual(viewModel.length, 2);
assert.strictEqual(viewModel.cellAt(0)?.getText(), 'var a = 1;');
@ -347,10 +351,11 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 0, end: 1 }, [{ start: 0, end: 1 }, { start: 3, end: 5 }]);
editor.setFocus({ start: 0, end: 1 });
editor.setSelections([{ start: 0, end: 1 }, { start: 3, end: 5 }]);
runDeleteAction(viewModel, viewModel.cellAt(1)!);
assert.strictEqual(viewModel.length, 4);
assert.deepStrictEqual(viewModel.getFocus(), { start: 0, end: 1 });
assert.deepStrictEqual(editor.getFocus(), { start: 0, end: 1 });
assert.deepStrictEqual(viewModel.getSelections(), [{ start: 0, end: 1 }, { start: 2, end: 4 }]);
});
});
@ -366,10 +371,11 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 0, end: 1 }, [{ start: 2, end: 3 }]);
editor.setFocus({ start: 0, end: 1 });
editor.setSelections([{ start: 2, end: 3 }]);
runDeleteAction(viewModel, viewModel.cellAt(0)!);
assert.strictEqual(viewModel.length, 4);
assert.deepStrictEqual(viewModel.getFocus(), { start: 0, end: 1 });
assert.deepStrictEqual(editor.getFocus(), { start: 0, end: 1 });
assert.deepStrictEqual(viewModel.getSelections(), [{ start: 1, end: 2 }]);
});
});
@ -385,10 +391,11 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 2, end: 3 }, [{ start: 3, end: 5 }]);
editor.setFocus({ start: 2, end: 3 });
editor.setSelections([{ start: 3, end: 5 }]);
runDeleteAction(viewModel, viewModel.cellAt(0)!);
assert.strictEqual(viewModel.length, 4);
assert.deepStrictEqual(viewModel.getFocus(), { start: 1, end: 2 });
assert.deepStrictEqual(editor.getFocus(), { start: 1, end: 2 });
assert.deepStrictEqual(viewModel.getSelections(), [{ start: 2, end: 4 }]);
});
});
@ -403,10 +410,11 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 2, end: 3 }, [{ start: 2, end: 3 }]);
editor.setFocus({ start: 2, end: 3 });
editor.setSelections([{ start: 2, end: 3 }]);
runDeleteAction(viewModel, viewModel.cellAt(2)!);
assert.strictEqual(viewModel.length, 2);
assert.deepStrictEqual(viewModel.getFocus(), { start: 1, end: 2 });
assert.deepStrictEqual(editor.getFocus(), { start: 1, end: 2 });
});
});
@ -420,10 +428,11 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 0, end: 1 }, [{ start: 0, end: 1 }, { start: 3, end: 4 }]);
editor.setFocus({ start: 0, end: 1 });
editor.setSelections([{ start: 0, end: 1 }, { start: 3, end: 4 }]);
runDeleteAction(viewModel, viewModel.cellAt(0)!);
assert.strictEqual(viewModel.length, 2);
assert.deepStrictEqual(viewModel.getFocus(), { start: 0, end: 1 });
assert.deepStrictEqual(editor.getFocus(), { start: 0, end: 1 });
});
});
@ -438,10 +447,11 @@ suite('CellOperations', () => {
],
async (editor) => {
const viewModel = editor.viewModel;
viewModel.setSelections({ start: 1, end: 2 }, [{ start: 1, end: 2 }, { start: 3, end: 5 }]);
editor.setFocus({ start: 1, end: 2 });
editor.setSelections([{ start: 1, end: 2 }, { start: 3, end: 5 }]);
runDeleteAction(viewModel, viewModel.cellAt(1)!);
assert.strictEqual(viewModel.length, 2);
assert.deepStrictEqual(viewModel.getFocus(), { start: 1, end: 2 });
assert.deepStrictEqual(editor.getFocus(), { start: 1, end: 2 });
});
});
});

View file

@ -31,7 +31,7 @@ import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
function getFocusedWebviewDelegate(accessor: ServicesAccessor): Webview | undefined {
const editorService = accessor.get(IEditorService);
const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
if (!editor?.hasFocus()) {
if (!editor?.hasEditorFocus()) {
return;
}

View file

@ -183,9 +183,9 @@ export interface ICommonNotebookEditor {
scheduleOutputHeightAck(cellInfo: ICommonCellInfo, outputId: string, height: number): void;
updateMarkupCellHeight(cellId: string, height: number, isInit: boolean): void;
setMarkupCellEditState(cellId: string, editState: CellEditState): void;
didStartDragMarkupCell(cellId: string, event: { dragOffsetY: number }): void;
didDragMarkupCell(cellId: string, event: { dragOffsetY: number }): void;
didDropMarkupCell(cellId: string, event: { dragOffsetY: number, ctrlKey: boolean, altKey: boolean }): void;
didStartDragMarkupCell(cellId: string, event: { dragOffsetY: number; }): void;
didDragMarkupCell(cellId: string, event: { dragOffsetY: number; }): void;
didDropMarkupCell(cellId: string, event: { dragOffsetY: number, ctrlKey: boolean, altKey: boolean; }): void;
didEndDragMarkupCell(cellId: string): void;
}
@ -357,10 +357,13 @@ export interface INotebookEditor extends ICommonNotebookEditor {
readonly onDidChangeVisibleRanges: Event<void>;
readonly onDidChangeSelection: Event<void>;
getSelections(): ICellRange[];
setSelections(selections: ICellRange[]): void;
getFocus(): ICellRange;
setFocus(focus: ICellRange): void;
visibleRanges: ICellRange[];
textModel?: NotebookTextModel;
getId(): string;
hasFocus(): boolean;
hasEditorFocus(): boolean;
isEmbedded: boolean;
@ -396,7 +399,7 @@ export interface INotebookEditor extends ICommonNotebookEditor {
*/
focus(): void;
hasFocus(): boolean;
hasEditorFocus(): boolean;
hasWebviewFocus(): boolean;
hasOutputTextSelection(): boolean;
@ -461,12 +464,12 @@ export interface INotebookEditor extends ICommonNotebookEditor {
/**
* Execute the given notebook cells
*/
executeNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>
executeNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>;
/**
* Cancel the given notebook cells
*/
cancelNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>
cancelNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>;
/**
* Get current active cell

View file

@ -456,10 +456,36 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
return this.viewModel?.getSelections() ?? [];
}
setSelections(selections: ICellRange[]) {
if (!this.hasModel()) {
return;
}
const focus = this.viewModel.getFocus();
this.viewModel.updateSelectionsState({
kind: SelectionStateType.Index,
focus: focus,
selections: selections
});
}
getFocus() {
return this.viewModel?.getFocus() ?? { start: 0, end: 0 };
}
setFocus(focus: ICellRange) {
if (!this.hasModel()) {
return;
}
const selections = this.viewModel.getSelections();
this.viewModel.updateSelectionsState({
kind: SelectionStateType.Index,
focus: focus,
selections: selections
});
}
getSelectionViewModels(): ICellViewModel[] {
if (!this.viewModel) {
return [];
@ -1603,7 +1629,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this.viewModel?.setEditorFocus(focused);
}
hasFocus() {
hasEditorFocus() {
return this._editorFocus.get() || false;
}
@ -1612,7 +1638,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}
hasOutputTextSelection() {
if (!this.hasFocus()) {
if (!this.hasEditorFocus()) {
return false;
}

View file

@ -56,7 +56,7 @@ export class CodeCell extends Disposable {
if (model && templateData.editor) {
templateData.editor.setModel(model);
viewCell.attachTextEditor(templateData.editor);
if (notebookEditor.getActiveCell() === viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasFocus()) {
if (notebookEditor.getActiveCell() === viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasEditorFocus()) {
templateData.editor?.focus();
}
@ -65,7 +65,7 @@ export class CodeCell extends Disposable {
this.onCellHeightChange(realContentHeight);
}
if (this.notebookEditor.getActiveCell() === this.viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasFocus()) {
if (this.notebookEditor.getActiveCell() === this.viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasEditorFocus()) {
templateData.editor?.focus();
}
}

View file

@ -382,7 +382,7 @@ export class StatefulMarkdownCell extends Disposable {
}
private focusEditorIfNeeded() {
if (this.viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasFocus()) {
if (this.viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasEditorFocus()) {
this.editor?.focus();
}
}

View file

@ -403,10 +403,6 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
}
}
setSelections(focus: ICellRange, selections: ICellRange[]) {
this.updateSelectionsState({ kind: SelectionStateType.Index, focus, selections }, 'model');
}
// selection change from list view's `setFocus` and `setSelection` should always use `source: view` to prevent events breaking the list view focus/selection change transaction
updateSelectionsState(state: ISelectionState, source: 'view' | 'model' = 'model') {
if (this._focused) {

View file

@ -21,7 +21,7 @@ import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/v
import { CellViewModel, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CellKind, CellUri, INotebookDiffEditorModel, INotebookEditorModel, IOutputDto, IResolvedNotebookEditorModel, NotebookCellMetadata, } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellUri, INotebookDiffEditorModel, INotebookEditorModel, IOutputDto, IResolvedNotebookEditorModel, NotebookCellMetadata, SelectionStateType, } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { IModelService } from 'vs/editor/common/services/modelService';
@ -201,6 +201,20 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic
}
override getFocus() { return viewModel.getFocus(); }
override getSelections() { return viewModel.getSelections(); }
override setFocus(focus: ICellRange) {
viewModel.updateSelectionsState({
kind: SelectionStateType.Index,
focus: focus,
selections: viewModel.getSelections()
});
}
override setSelections(selections: ICellRange[]) {
viewModel.updateSelectionsState({
kind: SelectionStateType.Index,
focus: viewModel.getFocus(),
selections: selections
});
}
override getViewIndex(cell: ICellViewModel) { return listViewInfoAccessor.getViewIndex(cell); }
override getCellRangeFromViewRange(startIndex: number, endIndex: number) { return listViewInfoAccessor.getCellRangeFromViewRange(startIndex, endIndex); }
override revealCellRangeInView() { }