Use existing property to avoid reacting to a model injected text changed event triggered via the cursor itself

This commit is contained in:
Alex Dima 2021-08-23 10:53:40 +02:00
parent d0af1bd6d8
commit e5e32317a2
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
3 changed files with 12 additions and 18 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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);
}