Skip to content

Commit 935a441

Browse files
committed
Have all commands go through the view model instead of the cursor
1 parent 993c159 commit 935a441

19 files changed

Lines changed: 651 additions & 652 deletions

File tree

src/vs/editor/browser/controller/coreCommands.ts

Lines changed: 154 additions & 160 deletions
Large diffs are not rendered by default.

src/vs/editor/browser/controller/mouseTarget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class HitTestRequest extends BareHitTestRequest {
420420
let mouseColumn = this.mouseColumn;
421421
if (position && position.column < this._ctx.model.getLineMaxColumn(position.lineNumber)) {
422422
// Most likely, the line contains foreign decorations...
423-
mouseColumn = CursorColumns.visibleColumnFromColumn(this._ctx.model.getLineContent(position.lineNumber), position.column, this._ctx.model.getOptions().tabSize) + 1;
423+
mouseColumn = CursorColumns.visibleColumnFromColumn(this._ctx.model.getLineContent(position.lineNumber), position.column, this._ctx.model.getTextModelOptions().tabSize) + 1;
424424
}
425425
return new MouseTarget(this.target, type, mouseColumn, position, range, detail);
426426
}

src/vs/editor/browser/editorBrowser.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
77
import { IMouseEvent, IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
88
import { IDisposable } from 'vs/base/common/lifecycle';
99
import { OverviewRulerPosition, ConfigurationChangedEvent, EditorLayoutInfo, IComputedEditorOptions, EditorOption, FindComputedEditorOptionValueById, IEditorOptions, IDiffEditorOptions } from 'vs/editor/common/config/editorOptions';
10-
import { ICursors } from 'vs/editor/common/controller/cursorCommon';
1110
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
1211
import { IPosition, Position } from 'vs/editor/common/core/position';
1312
import { IRange, Range } from 'vs/editor/common/core/range';
@@ -663,11 +662,6 @@ export interface ICodeEditor extends editorCommon.IEditor {
663662
*/
664663
executeCommands(source: string | null | undefined, commands: (editorCommon.ICommand | null)[]): void;
665664

666-
/**
667-
* @internal
668-
*/
669-
_getCursors(): ICursors | null;
670-
671665
/**
672666
* @internal
673667
*/
@@ -861,11 +855,6 @@ export interface IActiveCodeEditor extends ICodeEditor {
861855
*/
862856
getModel(): ITextModel;
863857

864-
/**
865-
* @internal
866-
*/
867-
_getCursors(): ICursors;
868-
869858
/**
870859
* @internal
871860
*/

src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class IndentGuidesOverlay extends DynamicViewOverlay {
112112

113113
const visibleStartLineNumber = ctx.visibleRange.startLineNumber;
114114
const visibleEndLineNumber = ctx.visibleRange.endLineNumber;
115-
const { indentSize } = this._context.model.getOptions();
115+
const { indentSize } = this._context.model.getTextModelOptions();
116116
const indentWidth = indentSize * this._spaceWidth;
117117
const scrollWidth = ctx.scrollWidth;
118118
const lineHeight = this._lineHeight;

src/vs/editor/browser/viewParts/minimap/minimap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ export class Minimap extends ViewPart implements IMinimapModel {
10041004
}
10051005

10061006
public getOptions(): TextModelResolvedOptions {
1007-
return this._context.model.getOptions();
1007+
return this._context.model.getTextModelOptions();
10081008
}
10091009

10101010
public revealLineNumber(lineNumber: number): void {

src/vs/editor/browser/viewParts/rulers/rulers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class Rulers extends ViewPart {
6464
}
6565

6666
if (currentCount < desiredCount) {
67-
const { tabSize } = this._context.model.getOptions();
67+
const { tabSize } = this._context.model.getTextModelOptions();
6868
const rulerWidth = tabSize;
6969
let addCount = desiredCount - currentCount;
7070
while (addCount > 0) {

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/
2424
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
2525
import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById, IEditorConstructionOptions, filterValidationDecorations } from 'vs/editor/common/config/editorOptions';
2626
import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor';
27-
import { CursorColumns, ICursors } from 'vs/editor/common/controller/cursorCommon';
27+
import { CursorColumns } from 'vs/editor/common/controller/cursorCommon';
2828
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
2929
import { IPosition, Position } from 'vs/editor/common/core/position';
3030
import { IRange, Range } from 'vs/editor/common/core/range';
@@ -1090,13 +1090,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
10901090
return false;
10911091
}
10921092

1093-
public _getCursors(): ICursors | null {
1094-
if (!this._modelData) {
1095-
return null;
1096-
}
1097-
return this._modelData.viewModel.getCursors();
1098-
}
1099-
11001093
public _getViewModel(): IViewModel | null {
11011094
if (!this._modelData) {
11021095
return null;
@@ -1544,7 +1537,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
15441537
if (this.isSimpleWidget) {
15451538
commandDelegate = {
15461539
executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => {
1547-
editorCommand.runCoreEditorCommand(this, viewModel, viewModel.getCursors(), args);
1540+
editorCommand.runCoreEditorCommand(viewModel, args);
15481541
},
15491542
paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => {
15501543
this._paste('keyboard', text, pasteOnNewLine, multicursorText, mode);
@@ -1568,7 +1561,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
15681561
} else {
15691562
commandDelegate = {
15701563
executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => {
1571-
editorCommand.runCoreEditorCommand(this, viewModel, viewModel.getCursors(), args);
1564+
editorCommand.runCoreEditorCommand(viewModel, args);
15721565
},
15731566
paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => {
15741567
const payload: editorCommon.PastePayload = { text, pasteOnNewLine, multicursorText, mode };

src/vs/editor/common/controller/cursor.ts

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
77
import { Emitter, Event } from 'vs/base/common/event';
88
import * as strings from 'vs/base/common/strings';
99
import { CursorCollection } from 'vs/editor/common/controller/cursorCollection';
10-
import { CursorColumns, CursorConfiguration, CursorContext, CursorState, EditOperationResult, EditOperationType, IColumnSelectData, ICursors, PartialCursorState, ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon';
10+
import { CursorColumns, CursorConfiguration, CursorContext, CursorState, EditOperationResult, EditOperationType, IColumnSelectData, PartialCursorState, ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon';
1111
import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations';
1212
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
1313
import { TypeOperations, TypeWithAutoClosingCommand } from 'vs/editor/common/controller/cursorTypeOperations';
@@ -16,10 +16,9 @@ import { Range, IRange } from 'vs/editor/common/core/range';
1616
import { ISelection, Selection, SelectionDirection } from 'vs/editor/common/core/selection';
1717
import * as editorCommon from 'vs/editor/common/editorCommon';
1818
import { ITextModel, TrackedRangeStickiness, IModelDeltaDecoration, ICursorStateComputer, IIdentifiedSingleEditOperation, IValidEditOperation } from 'vs/editor/common/model';
19-
import { RawContentChangedType, ModelRawContentChangedEvent, IModelLanguageChangedEvent } from 'vs/editor/common/model/textModelEvents';
19+
import { RawContentChangedType, ModelRawContentChangedEvent } from 'vs/editor/common/model/textModelEvents';
2020
import { ViewEventsCollector, VerticalRevealType, ViewCursorStateChangedEvent, ViewRevealRangeRequestEvent } from 'vs/editor/common/view/viewEvents';
2121
import { dispose, Disposable } from 'vs/base/common/lifecycle';
22-
import { EditorOption, ConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
2322
import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
2423

2524
export class CursorStateChangedEvent {
@@ -74,7 +73,7 @@ export class CursorModelState {
7473

7574
constructor(model: ITextModel, cursor: Cursor) {
7675
this.modelVersionId = model.getVersionId();
77-
this.cursorState = cursor.getAll();
76+
this.cursorState = cursor.getCursorStates();
7877
}
7978

8079
public equals(other: CursorModelState | null): boolean {
@@ -162,7 +161,7 @@ class AutoClosedAction {
162161
}
163162
}
164163

165-
export class Cursor extends Disposable implements ICursors {
164+
export class Cursor extends Disposable {
166165

167166
public static readonly MAX_CURSOR_COUNT = 10000;
168167

@@ -172,7 +171,6 @@ export class Cursor extends Disposable implements ICursors {
172171
private readonly _onDidChange: Emitter<CursorStateChangedEvent> = this._register(new Emitter<CursorStateChangedEvent>());
173172
public readonly onDidChange: Event<CursorStateChangedEvent> = this._onDidChange.event;
174173

175-
private readonly _configuration: editorCommon.IConfiguration;
176174
private readonly _model: ITextModel;
177175
private _knownModelVersionId: number;
178176
private readonly _viewModel: ICursorSimpleModel;
@@ -188,14 +186,13 @@ export class Cursor extends Disposable implements ICursors {
188186
private _autoClosedActions: AutoClosedAction[];
189187
private _prevEditOperationType: EditOperationType;
190188

191-
constructor(configuration: editorCommon.IConfiguration, model: ITextModel, viewModel: ICursorSimpleModel, coordinatesConverter: ICoordinatesConverter) {
189+
constructor(model: ITextModel, viewModel: ICursorSimpleModel, coordinatesConverter: ICoordinatesConverter, cursorConfig: CursorConfiguration) {
192190
super();
193-
this._configuration = configuration;
194191
this._model = model;
195192
this._knownModelVersionId = this._model.getVersionId();
196193
this._viewModel = viewModel;
197194
this._coordinatesConverter = coordinatesConverter;
198-
this.context = new CursorContext(this._configuration, this._model, this._viewModel, this._coordinatesConverter);
195+
this.context = new CursorContext(this._model, this._coordinatesConverter, cursorConfig);
199196
this._cursors = new CursorCollection(this.context);
200197

201198
this._hasFocus = false;
@@ -213,8 +210,8 @@ export class Cursor extends Disposable implements ICursors {
213210
super.dispose();
214211
}
215212

216-
private _updateCursorContext(): void {
217-
this.context = new CursorContext(this._configuration, this._model, this._viewModel, this._coordinatesConverter);
213+
public updateConfiguration(cursorConfig: CursorConfiguration): void {
214+
this.context = new CursorContext(this._model, this._coordinatesConverter, cursorConfig);
218215
this._cursors.updateContext(this.context);
219216
}
220217

@@ -230,25 +227,7 @@ export class Cursor extends Disposable implements ICursors {
230227
return;
231228
}
232229
// Ensure valid state
233-
this.setStates(eventsCollector, 'viewModel', CursorChangeReason.NotSet, this.getAll());
234-
}
235-
236-
public onDidChangeModelLanguage(e: IModelLanguageChangedEvent): void {
237-
this._updateCursorContext();
238-
}
239-
240-
public onDidChangeModelLanguageConfiguration(): void {
241-
this._updateCursorContext();
242-
}
243-
244-
public onDidChangeModelOptions(): void {
245-
this._updateCursorContext();
246-
}
247-
248-
public onDidChangeConfiguration(e: ConfigurationChangedEvent): void {
249-
if (CursorConfiguration.shouldRecreate(e)) {
250-
this._updateCursorContext();
251-
}
230+
this.setStates(eventsCollector, 'viewModel', CursorChangeReason.NotSet, this.getCursorStates());
252231
}
253232

254233
public setHasFocus(hasFocus: boolean): void {
@@ -271,15 +250,15 @@ export class Cursor extends Disposable implements ICursors {
271250

272251
// ------ some getters/setters
273252

274-
public getPrimaryCursor(): CursorState {
253+
public getPrimaryCursorState(): CursorState {
275254
return this._cursors.getPrimaryCursor();
276255
}
277256

278257
public getLastAddedCursorIndex(): number {
279258
return this._cursors.getLastAddedCursorIndex();
280259
}
281260

282-
public getAll(): CursorState[] {
261+
public getCursorStates(): CursorState[] {
283262
return this._cursors.getAll();
284263
}
285264

@@ -301,7 +280,7 @@ export class Cursor extends Disposable implements ICursors {
301280
return this._emitStateChangedIfNecessary(eventsCollector, source, reason, oldState, reachedMaxCursorCount);
302281
}
303282

304-
public setColumnSelectData(columnSelectData: IColumnSelectData): void {
283+
public setCursorColumnSelectData(columnSelectData: IColumnSelectData): void {
305284
this._columnSelectData = columnSelectData;
306285
}
307286

@@ -438,7 +417,7 @@ export class Cursor extends Disposable implements ICursors {
438417
return this._cursors.getBottomMostViewPosition();
439418
}
440419

441-
public getColumnSelectData(): IColumnSelectData {
420+
public getCursorColumnSelectData(): IColumnSelectData {
442421
if (this._columnSelectData) {
443422
return this._columnSelectData;
444423
}
@@ -448,9 +427,9 @@ export class Cursor extends Disposable implements ICursors {
448427
return {
449428
isReal: false,
450429
fromViewLineNumber: viewSelectionStart.lineNumber,
451-
fromViewVisualColumn: CursorColumns.visibleColumnFromColumn2(this.context.config, this.context.viewModel, viewSelectionStart),
430+
fromViewVisualColumn: CursorColumns.visibleColumnFromColumn2(this.context.cursorConfig, this._viewModel, viewSelectionStart),
452431
toViewLineNumber: viewPosition.lineNumber,
453-
toViewVisualColumn: CursorColumns.visibleColumnFromColumn2(this.context.config, this.context.viewModel, viewPosition),
432+
toViewVisualColumn: CursorColumns.visibleColumnFromColumn2(this.context.cursorConfig, this._viewModel, viewPosition),
454433
};
455434
}
456435

@@ -600,7 +579,7 @@ export class Cursor extends Disposable implements ICursors {
600579
}
601580
const closeChar = m[1];
602581

603-
const autoClosingPairsCandidates = this.context.config.autoClosingPairsClose2.get(closeChar);
582+
const autoClosingPairsCandidates = this.context.cursorConfig.autoClosingPairsClose2.get(closeChar);
604583
if (!autoClosingPairsCandidates || autoClosingPairsCandidates.length !== 1) {
605584
return null;
606585
}
@@ -661,7 +640,7 @@ export class Cursor extends Disposable implements ICursors {
661640
}
662641

663642
private _executeEdit(callback: () => void, eventsCollector: ViewEventsCollector, source: string | null | undefined, cursorChangeReason: CursorChangeReason = CursorChangeReason.NotSet): void {
664-
if (this._configuration.options.get(EditorOption.readOnly)) {
643+
if (this.context.cursorConfig.readOnly) {
665644
// we cannot edit when read only...
666645
this._onDidAttemptReadOnlyEdit.fire(undefined);
667646
return;
@@ -697,7 +676,7 @@ export class Cursor extends Disposable implements ICursors {
697676
if (!this._isDoingComposition && source === 'keyboard') {
698677
// composition finishes, let's check if we need to auto complete if necessary.
699678
const autoClosedCharacters = AutoClosedAction.getAllAutoClosedCharacters(this._autoClosedActions);
700-
this._executeEditOperation(TypeOperations.compositionEndWithInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this._selectionsWhenCompositionStarted, this.getSelections(), autoClosedCharacters));
679+
this._executeEditOperation(TypeOperations.compositionEndWithInterceptors(this._prevEditOperationType, this.context.cursorConfig, this._model, this._selectionsWhenCompositionStarted, this.getSelections(), autoClosedCharacters));
701680
this._selectionsWhenCompositionStarted = null;
702681
}
703682
}, eventsCollector, source);
@@ -716,32 +695,32 @@ export class Cursor extends Disposable implements ICursors {
716695

717696
// Here we must interpret each typed character individually
718697
const autoClosedCharacters = AutoClosedAction.getAllAutoClosedCharacters(this._autoClosedActions);
719-
this._executeEditOperation(TypeOperations.typeWithInterceptors(this._isDoingComposition, this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), autoClosedCharacters, chr));
698+
this._executeEditOperation(TypeOperations.typeWithInterceptors(this._isDoingComposition, this._prevEditOperationType, this.context.cursorConfig, this._model, this.getSelections(), autoClosedCharacters, chr));
720699

721700
offset += charLength;
722701
}
723702

724703
} else {
725-
this._executeEditOperation(TypeOperations.typeWithoutInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), text));
704+
this._executeEditOperation(TypeOperations.typeWithoutInterceptors(this._prevEditOperationType, this.context.cursorConfig, this._model, this.getSelections(), text));
726705
}
727706
}, eventsCollector, source);
728707
}
729708

730709
public replacePreviousChar(eventsCollector: ViewEventsCollector, text: string, replaceCharCnt: number, source?: string | null | undefined): void {
731710
this._executeEdit(() => {
732-
this._executeEditOperation(TypeOperations.replacePreviousChar(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), text, replaceCharCnt));
711+
this._executeEditOperation(TypeOperations.replacePreviousChar(this._prevEditOperationType, this.context.cursorConfig, this._model, this.getSelections(), text, replaceCharCnt));
733712
}, eventsCollector, source);
734713
}
735714

736715
public paste(eventsCollector: ViewEventsCollector, text: string, pasteOnNewLine: boolean, multicursorText?: string[] | null | undefined, source?: string | null | undefined): void {
737716
this._executeEdit(() => {
738-
this._executeEditOperation(TypeOperations.paste(this.context.config, this.context.model, this.getSelections(), text, pasteOnNewLine, multicursorText || []));
717+
this._executeEditOperation(TypeOperations.paste(this.context.cursorConfig, this._model, this.getSelections(), text, pasteOnNewLine, multicursorText || []));
739718
}, eventsCollector, source, CursorChangeReason.Paste);
740719
}
741720

742721
public cut(eventsCollector: ViewEventsCollector, source?: string | null | undefined): void {
743722
this._executeEdit(() => {
744-
this._executeEditOperation(DeleteOperations.cut(this.context.config, this.context.model, this.getSelections()));
723+
this._executeEditOperation(DeleteOperations.cut(this.context.cursorConfig, this._model, this.getSelections()));
745724
}, eventsCollector, source);
746725
}
747726

src/vs/editor/common/controller/cursorCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class CursorCollection {
226226
const currentSelection = current.selection;
227227
const nextSelection = next.selection;
228228

229-
if (!this.context.config.multiCursorMergeOverlapping) {
229+
if (!this.context.cursorConfig.multiCursorMergeOverlapping) {
230230
continue;
231231
}
232232

src/vs/editor/common/controller/cursorCommon.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,6 @@ export const enum EditOperationType {
4444
DeletingRight = 3
4545
}
4646

47-
export interface ICursors {
48-
readonly context: CursorContext;
49-
getPrimaryCursor(): CursorState;
50-
getLastAddedCursorIndex(): number;
51-
getAll(): CursorState[];
52-
53-
getColumnSelectData(): IColumnSelectData;
54-
setColumnSelectData(columnSelectData: IColumnSelectData): void;
55-
56-
getPrevEditOperationType(): EditOperationType;
57-
setPrevEditOperationType(type: EditOperationType): void;
58-
}
59-
6047
export interface CharacterMap {
6148
[char: string]: string;
6249
}
@@ -349,19 +336,13 @@ export class CursorContext {
349336
_cursorContextBrand: void;
350337

351338
public readonly model: ITextModel;
352-
public readonly viewModel: ICursorSimpleModel;
353339
public readonly coordinatesConverter: ICoordinatesConverter;
354-
public readonly config: CursorConfiguration;
340+
public readonly cursorConfig: CursorConfiguration;
355341

356-
constructor(configuration: IConfiguration, model: ITextModel, viewModel: ICursorSimpleModel, coordinatesConverter: ICoordinatesConverter) {
342+
constructor(model: ITextModel, coordinatesConverter: ICoordinatesConverter, cursorConfig: CursorConfiguration) {
357343
this.model = model;
358-
this.viewModel = viewModel;
359344
this.coordinatesConverter = coordinatesConverter;
360-
this.config = new CursorConfiguration(
361-
this.model.getLanguageIdentifier(),
362-
this.model.getOptions(),
363-
configuration
364-
);
345+
this.cursorConfig = cursorConfig;
365346
}
366347
}
367348

0 commit comments

Comments
 (0)