427
428
public pushEditOperation(beforeCursorState: Selection[] | null, editOperations: ISingleEditOperation[], cursorStateComputer: ICursorStateComputer | null, group?: UndoRedoGroup, reason: TextModelEditSource = EditSources.unknown({ name: 'pushEditOperation' })): Selection[] | null {
429
>
const editStackElement = this._getOrCreateEditStackElement(beforeCursorState, group);
editStack.ts
430
>
const inverseEditOperations = this._model.applyEdits(editOperations, true, reason);
431
>
const afterCursorState = EditStack._computeCursorState(cursorStateComputer, inverseEditOperations);
432
>
const textChanges = inverseEditOperations.map((op, index) => ({ index: index, textChange: op.textChange }));
433
>
textChanges.sort((a, b) => {
434
if (a.textChange.oldPosition === b.textChange.oldPosition) {
435
return a.index - b.index;
436
}
437
return a.textChange.oldPosition - b.textChange.oldPosition;
439
>
editStackElement.append(this._model, textChanges.map(op => op.textChange), getModelEOL(this._model), this._model.getAlternativeVersionId(), afterCursorState);
440
>
return afterCursorState;
441
>
}
442
443
private static _computeCursorState(cursorStateComputer: ICursorStateComputer | null, inverseEditOperations: IValidEditOperation[]): Selection[] | null {
445
>
return cursorStateComputer ? cursorStateComputer(inverseEditOperations) : null;
446
>
} catch (e) {
447
onUnexpectedError(e);
448
return null;
449
}
451
}