Use existing property to avoid reacting to a model injected text changed event triggered via the cursor itself
This commit is contained in:
parent
d0af1bd6d8
commit
e5e32317a2
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue