This commit is contained in:
rebornix 2021-02-23 08:14:58 -08:00
parent c257135247
commit 28a40e373c
2 changed files with 34 additions and 1 deletions

View file

@ -32,7 +32,7 @@ export class NotebookCellSelectionCollection extends Disposable {
private _primary: ICellRange | null = null;
private _selections: ICellRange[] = [];
private _selections: ICellRange[] = [{ start: 0, end: 0 }];
get selections(): ICellRange[] {
return this._selections;

View file

@ -0,0 +1,33 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { NotebookCellSelectionCollection } from 'vs/workbench/contrib/notebook/browser/viewModel/cellSelectionCollection';
suite('NotebookSelection', () => {
test('selection is never empty', function () {
const selectionCollection = new NotebookCellSelectionCollection();
assert.deepStrictEqual(selectionCollection.selections, [{ start: 0, end: 0 }]);
selectionCollection.setState(null, [], true);
assert.deepStrictEqual(selectionCollection.selections, [{ start: 0, end: 0 }]);
});
test('selections[0] is primary selection', function () {
const selectionCollection = new NotebookCellSelectionCollection();
selectionCollection.setState(null, [{ start: 0, end: 1 }, { start: 3, end: 5 }], true);
assert.deepStrictEqual(selectionCollection.selection, { start: 0, end: 1 });
assert.deepStrictEqual(selectionCollection.selections, [{ start: 0, end: 1 }, { start: 3, end: 5 }]);
selectionCollection.setState({ start: 0, end: 1 }, [{ start: 3, end: 5 }], true);
assert.deepStrictEqual(selectionCollection.selection, { start: 0, end: 1 });
assert.deepStrictEqual(selectionCollection.selections, [{ start: 0, end: 1 }, { start: 3, end: 5 }]);
selectionCollection.setState({ start: 0, end: 1 }, [], true);
assert.deepStrictEqual(selectionCollection.selection, { start: 0, end: 1 });
assert.deepStrictEqual(selectionCollection.selections, [{ start: 0, end: 1 }]);
});
});