mirror of
https://github.com/Microsoft/vscode
synced 2024-08-25 03:56:03 +00:00
Merge pull request #129247 from microsoft/hediet/fix-unnormalized-cursors-when-injected-text-changes
When injected text is added or removed, cursors in that line need to be normalized again
This commit is contained in:
commit
3dbdafcf7f
|
@ -15,7 +15,7 @@ import { Range, IRange } from 'vs/editor/common/core/range';
|
|||
import { ISelection, Selection, SelectionDirection } from 'vs/editor/common/core/selection';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { ITextModel, TrackedRangeStickiness, IModelDeltaDecoration, ICursorStateComputer, IIdentifiedSingleEditOperation, IValidEditOperation } from 'vs/editor/common/model';
|
||||
import { RawContentChangedType, ModelRawContentChangedEvent } from 'vs/editor/common/model/textModelEvents';
|
||||
import { RawContentChangedType, ModelRawContentChangedEvent, ModelInjectedTextChangedEvent } from 'vs/editor/common/model/textModelEvents';
|
||||
import { VerticalRevealType, ViewCursorStateChangedEvent, ViewRevealRangeRequestEvent } from 'vs/editor/common/view/viewEvents';
|
||||
import { dispose, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
|
||||
|
@ -328,31 +328,36 @@ export class CursorsController extends Disposable {
|
|||
this.revealPrimary(eventsCollector, 'restoreState', true, editorCommon.ScrollType.Immediate);
|
||||
}
|
||||
|
||||
public onModelContentChanged(eventsCollector: ViewModelEventsCollector, e: ModelRawContentChangedEvent): void {
|
||||
|
||||
this._knownModelVersionId = e.versionId;
|
||||
if (this._isHandling) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hadFlushEvent = e.containsEvent(RawContentChangedType.Flush);
|
||||
this._prevEditOperationType = EditOperationType.Other;
|
||||
|
||||
if (hadFlushEvent) {
|
||||
// a model.setValue() was called
|
||||
this._cursors.dispose();
|
||||
this._cursors = new CursorCollection(this.context);
|
||||
this._validateAutoClosedActions();
|
||||
this._emitStateChangedIfNecessary(eventsCollector, 'model', CursorChangeReason.ContentFlush, null, false);
|
||||
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.
|
||||
const selectionsFromMarkers = this._cursors.readSelectionFromMarkers();
|
||||
this.setStates(eventsCollector, 'modelChange', CursorChangeReason.RecoverFromMarkers, CursorState.fromModelSelections(selectionsFromMarkers));
|
||||
} else {
|
||||
if (this._hasFocus && e.resultingSelection && e.resultingSelection.length > 0) {
|
||||
const cursorState = CursorState.fromModelSelections(e.resultingSelection);
|
||||
if (this.setStates(eventsCollector, 'modelChange', e.isUndoing ? CursorChangeReason.Undo : e.isRedoing ? CursorChangeReason.Redo : CursorChangeReason.RecoverFromMarkers, cursorState)) {
|
||||
this._revealPrimaryCursor(eventsCollector, 'modelChange', VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth);
|
||||
}
|
||||
this._knownModelVersionId = e.versionId;
|
||||
if (this._isHandling) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hadFlushEvent = e.containsEvent(RawContentChangedType.Flush);
|
||||
this._prevEditOperationType = EditOperationType.Other;
|
||||
|
||||
if (hadFlushEvent) {
|
||||
// a model.setValue() was called
|
||||
this._cursors.dispose();
|
||||
this._cursors = new CursorCollection(this.context);
|
||||
this._validateAutoClosedActions();
|
||||
this._emitStateChangedIfNecessary(eventsCollector, 'model', CursorChangeReason.ContentFlush, null, false);
|
||||
} else {
|
||||
const selectionsFromMarkers = this._cursors.readSelectionFromMarkers();
|
||||
this.setStates(eventsCollector, 'modelChange', CursorChangeReason.RecoverFromMarkers, CursorState.fromModelSelections(selectionsFromMarkers));
|
||||
if (this._hasFocus && e.resultingSelection && e.resultingSelection.length > 0) {
|
||||
const cursorState = CursorState.fromModelSelections(e.resultingSelection);
|
||||
if (this.setStates(eventsCollector, 'modelChange', e.isUndoing ? CursorChangeReason.Undo : e.isRedoing ? CursorChangeReason.Redo : CursorChangeReason.RecoverFromMarkers, cursorState)) {
|
||||
this._revealPrimaryCursor(eventsCollector, 'modelChange', VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth);
|
||||
}
|
||||
} else {
|
||||
const selectionsFromMarkers = this._cursors.readSelectionFromMarkers();
|
||||
this.setStates(eventsCollector, 'modelChange', CursorChangeReason.RecoverFromMarkers, CursorState.fromModelSelections(selectionsFromMarkers));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -377,13 +377,11 @@ export class ViewModel extends Disposable implements IViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
if (e instanceof textModelEvents.ModelRawContentChangedEvent) {
|
||||
try {
|
||||
const eventsCollector = this._eventDispatcher.beginEmitViewEvents();
|
||||
this._cursor.onModelContentChanged(eventsCollector, e);
|
||||
} finally {
|
||||
this._eventDispatcher.endEmitViewEvents();
|
||||
}
|
||||
try {
|
||||
const eventsCollector = this._eventDispatcher.beginEmitViewEvents();
|
||||
this._cursor.onModelContentChanged(eventsCollector, e);
|
||||
} finally {
|
||||
this._eventDispatcher.endEmitViewEvents();
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in a new issue