From 261d075b4cb2391f2fd2a3f2f250a90504857558 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Fri, 11 Jun 2021 16:06:17 +0200 Subject: [PATCH 1/2] PrefixSumComputer renames. --- .../common/services/editorSimpleWorker.ts | 2 +- .../common/viewModel/prefixSumComputer.ts | 38 +++++----- .../viewModel/prefixSumComputer.test.ts | 74 +++++++++---------- .../api/common/extHostDocumentData.ts | 2 +- .../common/extHostNotebookConcatDocument.ts | 8 +- .../browser/contrib/find/findModel.ts | 2 +- .../browser/diff/diffNestedCellViewModel.ts | 4 +- .../notebook/browser/view/notebookCellList.ts | 16 ++-- .../browser/viewModel/codeCellViewModel.ts | 4 +- 9 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/vs/editor/common/services/editorSimpleWorker.ts b/src/vs/editor/common/services/editorSimpleWorker.ts index 4ad0c9d316b..e5e93423f69 100644 --- a/src/vs/editor/common/services/editorSimpleWorker.ts +++ b/src/vs/editor/common/services/editorSimpleWorker.ts @@ -235,7 +235,7 @@ class MirrorModel extends BaseMirrorModel implements ICommonModel { public offsetAt(position: IPosition): number { position = this._validatePosition(position); this._ensureLineStarts(); - return this._lineStarts!.getAccumulatedValue(position.lineNumber - 2) + (position.column - 1); + return this._lineStarts!.getPrefixSum(position.lineNumber - 2) + (position.column - 1); } public positionAt(offset: number): IPosition { diff --git a/src/vs/editor/common/viewModel/prefixSumComputer.ts b/src/vs/editor/common/viewModel/prefixSumComputer.ts index 6cb1312c07e..952a810a9d0 100644 --- a/src/vs/editor/common/viewModel/prefixSumComputer.ts +++ b/src/vs/editor/common/viewModel/prefixSumComputer.ts @@ -85,9 +85,9 @@ export class PrefixSumComputer { return true; } - public removeValues(startIndex: number, cnt: number): boolean { + public removeValues(startIndex: number, count: number): boolean { startIndex = toUint32(startIndex); - cnt = toUint32(cnt); + count = toUint32(count); const oldValues = this.values; const oldPrefixSum = this.prefixSum; @@ -96,18 +96,18 @@ export class PrefixSumComputer { return false; } - let maxCnt = oldValues.length - startIndex; - if (cnt >= maxCnt) { - cnt = maxCnt; + let maxCount = oldValues.length - startIndex; + if (count >= maxCount) { + count = maxCount; } - if (cnt === 0) { + if (count === 0) { return false; } - this.values = new Uint32Array(oldValues.length - cnt); + this.values = new Uint32Array(oldValues.length - count); this.values.set(oldValues.subarray(0, startIndex), 0); - this.values.set(oldValues.subarray(startIndex + cnt), startIndex); + this.values.set(oldValues.subarray(startIndex + count), startIndex); this.prefixSum = new Uint32Array(this.values.length); if (startIndex - 1 < this.prefixSumValidIndex[0]) { @@ -119,23 +119,23 @@ export class PrefixSumComputer { return true; } - public getTotalValue(): number { + public getTotalSum(): number { if (this.values.length === 0) { return 0; } - return this._getAccumulatedValue(this.values.length - 1); + return this._getPrefixSum(this.values.length - 1); } - public getAccumulatedValue(index: number): number { + public getPrefixSum(index: number): number { if (index < 0) { return 0; } index = toUint32(index); - return this._getAccumulatedValue(index); + return this._getPrefixSum(index); } - private _getAccumulatedValue(index: number): number { + private _getPrefixSum(index: number): number { if (index <= this.prefixSumValidIndex[0]) { return this.prefixSum[index]; } @@ -157,11 +157,11 @@ export class PrefixSumComputer { return this.prefixSum[index]; } - public getIndexOf(accumulatedValue: number): PrefixSumIndexOfResult { - accumulatedValue = Math.floor(accumulatedValue); //@perf + public getIndexOf(sum: number): PrefixSumIndexOfResult { + sum = Math.floor(sum); //@perf // Compute all sums (to get a fully valid prefixSum) - this.getTotalValue(); + this.getTotalSum(); let low = 0; let high = this.values.length - 1; @@ -175,15 +175,15 @@ export class PrefixSumComputer { midStop = this.prefixSum[mid]; midStart = midStop - this.values[mid]; - if (accumulatedValue < midStart) { + if (sum < midStart) { high = mid - 1; - } else if (accumulatedValue >= midStop) { + } else if (sum >= midStop) { low = mid + 1; } else { break; } } - return new PrefixSumIndexOfResult(mid, accumulatedValue - midStart); + return new PrefixSumIndexOfResult(mid, sum - midStart); } } diff --git a/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts b/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts index 80df1a94eb2..0ac5ed2672d 100644 --- a/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts +++ b/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts @@ -22,13 +22,13 @@ suite('Editor ViewModel - PrefixSumComputer', () => { let indexOfResult: PrefixSumIndexOfResult; let psc = new PrefixSumComputer(toUint32Array([1, 1, 2, 1, 3])); - assert.strictEqual(psc.getTotalValue(), 8); - assert.strictEqual(psc.getAccumulatedValue(-1), 0); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 2); - assert.strictEqual(psc.getAccumulatedValue(2), 4); - assert.strictEqual(psc.getAccumulatedValue(3), 5); - assert.strictEqual(psc.getAccumulatedValue(4), 8); + assert.strictEqual(psc.getTotalSum(), 8); + assert.strictEqual(psc.getPrefixSum(-1), 0); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 2); + assert.strictEqual(psc.getPrefixSum(2), 4); + assert.strictEqual(psc.getPrefixSum(3), 5); + assert.strictEqual(psc.getPrefixSum(4), 8); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -59,21 +59,21 @@ suite('Editor ViewModel - PrefixSumComputer', () => { // [1, 2, 2, 1, 3] psc.changeValue(1, 2); - assert.strictEqual(psc.getTotalValue(), 9); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 3); - assert.strictEqual(psc.getAccumulatedValue(2), 5); - assert.strictEqual(psc.getAccumulatedValue(3), 6); - assert.strictEqual(psc.getAccumulatedValue(4), 9); + assert.strictEqual(psc.getTotalSum(), 9); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 3); + assert.strictEqual(psc.getPrefixSum(2), 5); + assert.strictEqual(psc.getPrefixSum(3), 6); + assert.strictEqual(psc.getPrefixSum(4), 9); // [1, 0, 2, 1, 3] psc.changeValue(1, 0); - assert.strictEqual(psc.getTotalValue(), 7); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 1); - assert.strictEqual(psc.getAccumulatedValue(2), 3); - assert.strictEqual(psc.getAccumulatedValue(3), 4); - assert.strictEqual(psc.getAccumulatedValue(4), 7); + assert.strictEqual(psc.getTotalSum(), 7); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 1); + assert.strictEqual(psc.getPrefixSum(2), 3); + assert.strictEqual(psc.getPrefixSum(3), 4); + assert.strictEqual(psc.getPrefixSum(4), 7); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -101,12 +101,12 @@ suite('Editor ViewModel - PrefixSumComputer', () => { // [1, 0, 0, 1, 3] psc.changeValue(2, 0); - assert.strictEqual(psc.getTotalValue(), 5); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 1); - assert.strictEqual(psc.getAccumulatedValue(2), 1); - assert.strictEqual(psc.getAccumulatedValue(3), 2); - assert.strictEqual(psc.getAccumulatedValue(4), 5); + assert.strictEqual(psc.getTotalSum(), 5); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 1); + assert.strictEqual(psc.getPrefixSum(2), 1); + assert.strictEqual(psc.getPrefixSum(3), 2); + assert.strictEqual(psc.getPrefixSum(4), 5); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -128,12 +128,12 @@ suite('Editor ViewModel - PrefixSumComputer', () => { // [1, 0, 0, 0, 3] psc.changeValue(3, 0); - assert.strictEqual(psc.getTotalValue(), 4); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 1); - assert.strictEqual(psc.getAccumulatedValue(2), 1); - assert.strictEqual(psc.getAccumulatedValue(3), 1); - assert.strictEqual(psc.getAccumulatedValue(4), 4); + assert.strictEqual(psc.getTotalSum(), 4); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 1); + assert.strictEqual(psc.getPrefixSum(2), 1); + assert.strictEqual(psc.getPrefixSum(3), 1); + assert.strictEqual(psc.getPrefixSum(4), 4); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -154,12 +154,12 @@ suite('Editor ViewModel - PrefixSumComputer', () => { psc.changeValue(1, 1); psc.changeValue(3, 1); psc.changeValue(4, 1); - assert.strictEqual(psc.getTotalValue(), 4); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 2); - assert.strictEqual(psc.getAccumulatedValue(2), 2); - assert.strictEqual(psc.getAccumulatedValue(3), 3); - assert.strictEqual(psc.getAccumulatedValue(4), 4); + assert.strictEqual(psc.getTotalSum(), 4); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 2); + assert.strictEqual(psc.getPrefixSum(2), 2); + assert.strictEqual(psc.getPrefixSum(3), 3); + assert.strictEqual(psc.getPrefixSum(4), 4); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); diff --git a/src/vs/workbench/api/common/extHostDocumentData.ts b/src/vs/workbench/api/common/extHostDocumentData.ts index d244a16b8aa..78e12d7a47c 100644 --- a/src/vs/workbench/api/common/extHostDocumentData.ts +++ b/src/vs/workbench/api/common/extHostDocumentData.ts @@ -143,7 +143,7 @@ export class ExtHostDocumentData extends MirrorTextModel { private _offsetAt(position: vscode.Position): number { position = this._validatePosition(position); this._ensureLineStarts(); - return this._lineStarts!.getAccumulatedValue(position.line - 1) + position.character; + return this._lineStarts!.getPrefixSum(position.line - 1) + position.character; } private _positionAt(offset: number): vscode.Position { diff --git a/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts b/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts index 215975bdfd2..d25c8dfe06d 100644 --- a/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts +++ b/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts @@ -123,7 +123,7 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD offsetAt(position: vscode.Position): number { const idx = this._cellLines.getIndexOf(position.line); - const offset1 = this._cellLengths.getAccumulatedValue(idx.index - 1); + const offset1 = this._cellLengths.getPrefixSum(idx.index - 1); const offset2 = this._cells[idx.index].document.offsetAt(position.with(idx.remainder)); return offset1 + offset2; } @@ -131,13 +131,13 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD positionAt(locationOrOffset: vscode.Location | number): vscode.Position { if (typeof locationOrOffset === 'number') { const idx = this._cellLengths.getIndexOf(locationOrOffset); - const lineCount = this._cellLines.getAccumulatedValue(idx.index - 1); + const lineCount = this._cellLines.getPrefixSum(idx.index - 1); return this._cells[idx.index].document.positionAt(idx.remainder).translate(lineCount); } const idx = this._cellUris.get(locationOrOffset.uri); if (idx !== undefined) { - const line = this._cellLines.getAccumulatedValue(idx - 1); + const line = this._cellLines.getPrefixSum(idx - 1); return new types.Position(line + locationOrOffset.range.start.line, locationOrOffset.range.start.character); } // do better? @@ -180,7 +180,7 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD const cellPosition = new types.Position(startIdx.remainder, position.character); const validCellPosition = this._cells[startIdx.index].document.validatePosition(cellPosition); - const line = this._cellLines.getAccumulatedValue(startIdx.index - 1); + const line = this._cellLines.getPrefixSum(startIdx.index - 1); return new types.Position(line + validCellPosition.line, validCellPosition.character); } } diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts b/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts index 3e6d07b7822..99da66dff8e 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts @@ -88,7 +88,7 @@ export class FindModel extends Disposable { } else { // const currIndex = this._findMatchesStarts!.getIndexOf(this._currentMatch); // currCell = this._findMatches[currIndex.index].cell; - const totalVal = this._findMatchesStarts.getTotalValue(); + const totalVal = this._findMatchesStarts.getTotalSum(); if (this._currentMatch === -1) { this._currentMatch = previous ? totalVal - 1 : 0; } else { diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts index 84ef80fbea3..bf8c441d9a5 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts @@ -111,7 +111,7 @@ export class DiffNestedCellViewModel extends Disposable implements IDiffNestedCe throw new Error('Output index out of range!'); } - return this._outputsTop!.getAccumulatedValue(index - 1); + return this._outputsTop!.getPrefixSum(index - 1); } updateOutputHeight(index: number, height: number): void { @@ -129,6 +129,6 @@ export class DiffNestedCellViewModel extends Disposable implements IDiffNestedCe getOutputTotalHeight() { this._ensureOutputsTop(); - return this._outputsTop?.getTotalValue() ?? 0; + return this._outputsTop?.getTotalSum() ?? 0; } } diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts index 5584ff93977..2d7032b81a4 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts @@ -469,7 +469,7 @@ export class NotebookCellList extends WorkbenchList implements ID return viewIndex; } - const modelIndex = this.hiddenRangesPrefixSum.getAccumulatedValue(viewIndex - 1); + const modelIndex = this.hiddenRangesPrefixSum.getPrefixSum(viewIndex - 1); return modelIndex; } @@ -486,9 +486,9 @@ export class NotebookCellList extends WorkbenchList implements ID const viewIndexInfo = this.hiddenRangesPrefixSum.getIndexOf(modelIndex); if (viewIndexInfo.remainder !== 0) { - if (modelIndex >= this.hiddenRangesPrefixSum.getTotalValue()) { + if (modelIndex >= this.hiddenRangesPrefixSum.getTotalSum()) { // it's already after the last hidden range - return modelIndex - (this.hiddenRangesPrefixSum.getTotalValue() - this.hiddenRangesPrefixSum.getCount()); + return modelIndex - (this.hiddenRangesPrefixSum.getTotalSum() - this.hiddenRangesPrefixSum.getCount()); } return undefined; } else { @@ -504,7 +504,7 @@ export class NotebookCellList extends WorkbenchList implements ID let modelIndex = topModelIndex; while (index <= bottomViewIndex) { - const accu = this.hiddenRangesPrefixSum!.getAccumulatedValue(index); + const accu = this.hiddenRangesPrefixSum!.getPrefixSum(index); if (accu === modelIndex + 1) { // no hidden area after it if (stack.length) { @@ -575,8 +575,8 @@ export class NotebookCellList extends WorkbenchList implements ID const viewIndexInfo = this.hiddenRangesPrefixSum.getIndexOf(modelIndex); if (viewIndexInfo.remainder !== 0) { - if (modelIndex >= this.hiddenRangesPrefixSum.getTotalValue()) { - return modelIndex - (this.hiddenRangesPrefixSum.getTotalValue() - this.hiddenRangesPrefixSum.getCount()); + if (modelIndex >= this.hiddenRangesPrefixSum.getTotalSum()) { + return modelIndex - (this.hiddenRangesPrefixSum.getTotalSum() - this.hiddenRangesPrefixSum.getCount()); } } @@ -591,8 +591,8 @@ export class NotebookCellList extends WorkbenchList implements ID const viewIndexInfo = this.hiddenRangesPrefixSum.getIndexOf(modelIndex); if (viewIndexInfo.remainder !== 0) { - if (modelIndex >= this.hiddenRangesPrefixSum.getTotalValue()) { - return modelIndex - (this.hiddenRangesPrefixSum.getTotalValue() - this.hiddenRangesPrefixSum.getCount()); + if (modelIndex >= this.hiddenRangesPrefixSum.getTotalSum()) { + return modelIndex - (this.hiddenRangesPrefixSum.getTotalSum() - this.hiddenRangesPrefixSum.getCount()); } } diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts index c2673fa89ea..83d43339338 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts @@ -162,7 +162,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod const notebookLayoutConfiguration = this.viewContext.notebookOptions.getLayoutConfiguration(); const bottomToolbarDimensions = this.viewContext.notebookOptions.computeBottomToolbarDimensions(); const outputShowMoreContainerHeight = state.outputShowMoreContainerHeight ? state.outputShowMoreContainerHeight : this._layoutInfo.outputShowMoreContainerHeight; - let outputTotalHeight = Math.max(this._outputMinHeight, this.metadata.outputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalValue()); + let outputTotalHeight = Math.max(this._outputMinHeight, this.metadata.outputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalSum()); const originalLayout = this.layoutInfo; if (!this.metadata.inputCollapsed) { @@ -371,7 +371,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod throw new Error('Output index out of range!'); } - return this._outputsTop!.getAccumulatedValue(index - 1); + return this._outputsTop!.getPrefixSum(index - 1); } getOutputOffset(index: number): number { From 7f93f38f7b71923a6cb1dac5df458c4a4cb0e44a Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Fri, 11 Jun 2021 16:45:23 +0200 Subject: [PATCH 2/2] * Cursor -> CursorsController * OneCursor -> Cursor --- src/vs/editor/browser/widget/codeEditorWidget.ts | 4 ++-- src/vs/editor/common/controller/cursor.ts | 8 ++++---- .../editor/common/controller/cursorCollection.ts | 14 +++++++------- src/vs/editor/common/controller/oneCursor.ts | 5 ++++- src/vs/editor/common/viewModel/viewModelImpl.ts | 6 +++--- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 977e55d180b..96d924d2e7c 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -24,7 +24,7 @@ import { ICommandDelegate } from 'vs/editor/browser/view/viewController'; import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl'; import { ViewUserInputEvents } from 'vs/editor/browser/view/viewUserInputEvents'; import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById, filterValidationDecorations } from 'vs/editor/common/config/editorOptions'; -import { Cursor } from 'vs/editor/common/controller/cursor'; +import { CursorsController } from 'vs/editor/common/controller/cursor'; import { CursorColumns } from 'vs/editor/common/controller/cursorCommon'; import { CursorChangeReason, ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { IPosition, Position } from 'vs/editor/common/core/position'; @@ -1540,7 +1540,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE break; case OutgoingViewModelEventKind.CursorStateChanged: { if (e.reachedMaxCursorCount) { - this._notificationService.warn(nls.localize('cursors.maximum', "The number of cursors has been limited to {0}.", Cursor.MAX_CURSOR_COUNT)); + this._notificationService.warn(nls.localize('cursors.maximum', "The number of cursors has been limited to {0}.", CursorsController.MAX_CURSOR_COUNT)); } const positions: Position[] = []; diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index e2297a6be81..2ec7d252ac2 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -29,7 +29,7 @@ export class CursorModelState { public readonly modelVersionId: number; public readonly cursorState: CursorState[]; - constructor(model: ITextModel, cursor: Cursor) { + constructor(model: ITextModel, cursor: CursorsController) { this.modelVersionId = model.getVersionId(); this.cursorState = cursor.getCursorStates(); } @@ -119,7 +119,7 @@ class AutoClosedAction { } } -export class Cursor extends Disposable { +export class CursorsController extends Disposable { public static readonly MAX_CURSOR_COUNT = 10000; @@ -216,8 +216,8 @@ export class Cursor extends Disposable { public setStates(eventsCollector: ViewModelEventsCollector, source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): boolean { let reachedMaxCursorCount = false; - if (states !== null && states.length > Cursor.MAX_CURSOR_COUNT) { - states = states.slice(0, Cursor.MAX_CURSOR_COUNT); + if (states !== null && states.length > CursorsController.MAX_CURSOR_COUNT) { + states = states.slice(0, CursorsController.MAX_CURSOR_COUNT); reachedMaxCursorCount = true; } diff --git a/src/vs/editor/common/controller/cursorCollection.ts b/src/vs/editor/common/controller/cursorCollection.ts index 746039533ad..9cc5b6dd40f 100644 --- a/src/vs/editor/common/controller/cursorCollection.ts +++ b/src/vs/editor/common/controller/cursorCollection.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { CursorContext, CursorState, PartialCursorState } from 'vs/editor/common/controller/cursorCommon'; -import { OneCursor } from 'vs/editor/common/controller/oneCursor'; +import { Cursor } from 'vs/editor/common/controller/oneCursor'; import { Position } from 'vs/editor/common/core/position'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; @@ -12,15 +12,15 @@ export class CursorCollection { private context: CursorContext; - private primaryCursor: OneCursor; - private secondaryCursors: OneCursor[]; + private primaryCursor: Cursor; + private secondaryCursors: Cursor[]; // An index which identifies the last cursor that was added / moved (think Ctrl+drag) private lastAddedCursorIndex: number; constructor(context: CursorContext) { this.context = context; - this.primaryCursor = new OneCursor(context); + this.primaryCursor = new Cursor(context); this.secondaryCursors = []; this.lastAddedCursorIndex = 0; } @@ -167,7 +167,7 @@ export class CursorCollection { } private _addSecondaryCursor(): void { - this.secondaryCursors.push(new OneCursor(this.context)); + this.secondaryCursors.push(new Cursor(this.context)); this.lastAddedCursorIndex = this.secondaryCursors.length; } @@ -186,8 +186,8 @@ export class CursorCollection { this.secondaryCursors.splice(removeIndex, 1); } - private _getAll(): OneCursor[] { - let result: OneCursor[] = []; + private _getAll(): Cursor[] { + let result: Cursor[] = []; result[0] = this.primaryCursor; for (let i = 0, len = this.secondaryCursors.length; i < len; i++) { result[i + 1] = this.secondaryCursors[i]; diff --git a/src/vs/editor/common/controller/oneCursor.ts b/src/vs/editor/common/controller/oneCursor.ts index f79fafe21ae..f32a1b43c64 100644 --- a/src/vs/editor/common/controller/oneCursor.ts +++ b/src/vs/editor/common/controller/oneCursor.ts @@ -9,7 +9,10 @@ import { Range } from 'vs/editor/common/core/range'; import { Selection, SelectionDirection } from 'vs/editor/common/core/selection'; import { TrackedRangeStickiness } from 'vs/editor/common/model'; -export class OneCursor { +/** + * Represents a single cursor. +*/ +export class Cursor { public modelState!: SingleCursorState; public viewState!: SingleCursorState; diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 2d37d247f66..fd971ba5bf0 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -26,7 +26,7 @@ import { ViewModelDecorations } from 'vs/editor/common/viewModel/viewModelDecora import { RunOnceScheduler } from 'vs/base/common/async'; import * as platform from 'vs/base/common/platform'; import { EditorTheme } from 'vs/editor/common/view/viewContext'; -import { Cursor } from 'vs/editor/common/controller/cursor'; +import { CursorsController } from 'vs/editor/common/controller/cursor'; import { PartialCursorState, CursorState, IColumnSelectData, EditOperationType, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout'; @@ -52,7 +52,7 @@ export class ViewModel extends Disposable implements IViewModel { private readonly _lines: IViewModelLinesCollection; public readonly coordinatesConverter: ICoordinatesConverter; public readonly viewLayout: ViewLayout; - private readonly _cursor: Cursor; + private readonly _cursor: CursorsController; private readonly _decorations: ViewModelDecorations; constructor( @@ -103,7 +103,7 @@ export class ViewModel extends Disposable implements IViewModel { this.coordinatesConverter = this._lines.createCoordinatesConverter(); - this._cursor = this._register(new Cursor(model, this, this.coordinatesConverter, this.cursorConfig)); + this._cursor = this._register(new CursorsController(model, this, this.coordinatesConverter, this.cursorConfig)); this.viewLayout = this._register(new ViewLayout(this._configuration, this.getLineCount(), scheduleAtNextAnimationFrame));