From e898b8d0d0bba0422db064cddbcadd2d83023a25 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Tue, 24 Aug 2021 00:30:38 +0200 Subject: [PATCH] Prevents cursor from entering injected text for good. --- src/vs/editor/common/controller/cursor.ts | 40 +++++------------------ 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index bd018198d0c..4640244964d 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -335,15 +335,15 @@ export class CursorsController extends Disposable { // 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); + // 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. + // _isHandling prevents that. + this._isHandling = true; + try { + this.setStates(eventsCollector, 'modelChange', CursorChangeReason.NotSet, this.getCursorStates()); + } finally { + this._isHandling = false; } } else { this._knownModelVersionId = e.versionId; @@ -731,28 +731,6 @@ export class CursorsController extends Disposable { } } -function didStateChange(currentStates: CursorState[], newStates: PartialCursorState[]): boolean { - if (currentStates.length !== newStates.length) { - return true; - } - - for (let i = 0; i < currentStates.length; i++) { - const curState = currentStates[i]; - const newState = newStates[i]; - if (newState.modelState) { - if (!newState.modelState.equals(curState.modelState)) { - return true; - } - } - if (newState.viewState) { - if (!newState.viewState.equals(curState.viewState)) { - return true; - } - } - } - return false; -} - interface IExecContext { readonly model: ITextModel; readonly selectionsBefore: Selection[];