From e5e32317a296a2ce1aab0045eb385e214ac218e7 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 23 Aug 2021 10:53:40 +0200 Subject: [PATCH] Use existing property to avoid reacting to a model injected text changed event triggered via the cursor itself --- src/vs/editor/common/controller/cursor.ts | 22 ++++++++++--------- .../common/controller/cursorCollection.ts | 4 ---- src/vs/editor/common/controller/oneCursor.ts | 4 ---- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index e9079fa9519..bd018198d0c 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -331,17 +331,19 @@ export class CursorsController extends Disposable { public onModelContentChanged(eventsCollector: ViewModelEventsCollector, e: ModelRawContentChangedEvent | ModelInjectedTextChangedEvent): void { if (e instanceof ModelInjectedTextChangedEvent) { // If injected texts change, the view positions of all cursors need to be updated. - if (this._cursors.hasMarkers()) { - const selectionsFromMarkers = this._cursors.readSelectionFromMarkers(); - const newState = CursorState.fromModelSelections(selectionsFromMarkers); + if (this._isHandling) { + // The view positions will be updated when handling finishes + return; + } + const selectionsFromMarkers = this._cursors.readSelectionFromMarkers(); + const newState = CursorState.fromModelSelections(selectionsFromMarkers); - if (didStateChange(this.getCursorStates(), newState || [])) { - // setStates might remove markers, which could trigger a decoration change. - // If there are injected text decorations for that line, `onModelContentChanged` is emitted again - // and an endless recursion happens. - // This is why we only call setStates if we really need to (this fixes recursion). - this.setStates(eventsCollector, 'modelChange', CursorChangeReason.RecoverFromMarkers, newState); - } + if (didStateChange(this.getCursorStates(), newState || [])) { + // setStates might remove markers, which could trigger a decoration change. + // If there are injected text decorations for that line, `onModelContentChanged` is emitted again + // and an endless recursion happens. + // This is why we only call setStates if we really need to (this fixes recursion). + this.setStates(eventsCollector, 'modelChange', CursorChangeReason.RecoverFromMarkers, newState); } } else { this._knownModelVersionId = e.versionId; diff --git a/src/vs/editor/common/controller/cursorCollection.ts b/src/vs/editor/common/controller/cursorCollection.ts index 7c45b09c8df..9cc5b6dd40f 100644 --- a/src/vs/editor/common/controller/cursorCollection.ts +++ b/src/vs/editor/common/controller/cursorCollection.ts @@ -64,10 +64,6 @@ export class CursorCollection { return result; } - public hasMarkers() { - return this.primaryCursor.hasMarker() && this.secondaryCursors.every(c => c.hasMarker()); - } - public getAll(): CursorState[] { let result: CursorState[] = []; result[0] = this.primaryCursor.asCursorState(); diff --git a/src/vs/editor/common/controller/oneCursor.ts b/src/vs/editor/common/controller/oneCursor.ts index f7221eb027d..bb07a4da717 100644 --- a/src/vs/editor/common/controller/oneCursor.ts +++ b/src/vs/editor/common/controller/oneCursor.ts @@ -69,10 +69,6 @@ export class Cursor { return new Selection(range.endLineNumber, range.endColumn, range.startLineNumber, range.startColumn); } - public hasMarker(): boolean { - return this._trackSelection; - } - public ensureValidState(context: CursorContext): void { this._setState(context, this.modelState, this.viewState); }