Skip to content

Commit 985eea1

Browse files
committed
Relax method signature
1 parent 94fe174 commit 985eea1

4 files changed

Lines changed: 21 additions & 19 deletions

File tree

src/vs/editor/common/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ export interface ITextModel {
10771077
* @param cursorStateComputer A callback that can compute the resulting cursors state after the edit operations have been executed.
10781078
* @return The cursor state returned by the `cursorStateComputer`.
10791079
*/
1080-
pushEditOperations(beforeCursorState: Selection[], editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;
1080+
pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;
10811081

10821082
/**
10831083
* Change the end of line sequence. This is the preferred way of

src/vs/editor/common/model/editStack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class EditStackElement implements IUndoRedoElement {
7575
}
7676
}
7777

78-
export class MultiEditStackElement implements IUndoRedoElement {
78+
export class MultiModelEditStackElement implements IUndoRedoElement {
7979

8080
public readonly label: string;
8181
private _isOpen: boolean;
@@ -185,7 +185,7 @@ export class EditStack {
185185
editStackElement.append(this._model, [], getModelEOL(this._model), this._model.getAlternativeVersionId(), null);
186186
}
187187

188-
public pushEditOperation(beforeCursorState: Selection[], editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer | null): Selection[] | null {
188+
public pushEditOperation(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer | null): Selection[] | null {
189189
const editStackElement = this._getOrCreateEditStackElement(beforeCursorState);
190190
const inverseEditOperations = this._model.applyEdits(editOperations);
191191
const afterCursorState = EditStack._computeCursorState(cursorStateComputer, inverseEditOperations);

src/vs/editor/common/model/textModel.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ export class TextModel extends Disposable implements model.ITextModel {
11871187
return result;
11881188
}
11891189

1190-
public pushEditOperations(beforeCursorState: Selection[], editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
1190+
public pushEditOperations(beforeCursorState: Selection[] | null, editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
11911191
try {
11921192
this._onDidChangeDecorations.beginDeferredEmit();
11931193
this._eventEmitter.beginDeferredEmit();
@@ -1198,7 +1198,7 @@ export class TextModel extends Disposable implements model.ITextModel {
11981198
}
11991199
}
12001200

1201-
private _pushEditOperations(beforeCursorState: Selection[], editOperations: model.ValidAnnotatedEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
1201+
private _pushEditOperations(beforeCursorState: Selection[] | null, editOperations: model.ValidAnnotatedEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
12021202
if (this._options.trimAutoWhitespace && this._trimAutoWhitespaceLines) {
12031203
// Go through each saved line number and insert a trim whitespace edit
12041204
// if it is safe to do so (no conflicts with other edits).
@@ -1213,22 +1213,24 @@ export class TextModel extends Disposable implements model.ITextModel {
12131213
// Sometimes, auto-formatters change ranges automatically which can cause undesired auto whitespace trimming near the cursor
12141214
// We'll use the following heuristic: if the edits occur near the cursor, then it's ok to trim auto whitespace
12151215
let editsAreNearCursors = true;
1216-
for (let i = 0, len = beforeCursorState.length; i < len; i++) {
1217-
let sel = beforeCursorState[i];
1218-
let foundEditNearSel = false;
1219-
for (let j = 0, lenJ = incomingEdits.length; j < lenJ; j++) {
1220-
let editRange = incomingEdits[j].range;
1221-
let selIsAbove = editRange.startLineNumber > sel.endLineNumber;
1222-
let selIsBelow = sel.startLineNumber > editRange.endLineNumber;
1223-
if (!selIsAbove && !selIsBelow) {
1224-
foundEditNearSel = true;
1216+
if (beforeCursorState) {
1217+
for (let i = 0, len = beforeCursorState.length; i < len; i++) {
1218+
let sel = beforeCursorState[i];
1219+
let foundEditNearSel = false;
1220+
for (let j = 0, lenJ = incomingEdits.length; j < lenJ; j++) {
1221+
let editRange = incomingEdits[j].range;
1222+
let selIsAbove = editRange.startLineNumber > sel.endLineNumber;
1223+
let selIsBelow = sel.startLineNumber > editRange.endLineNumber;
1224+
if (!selIsAbove && !selIsBelow) {
1225+
foundEditNearSel = true;
1226+
break;
1227+
}
1228+
}
1229+
if (!foundEditNearSel) {
1230+
editsAreNearCursors = false;
12251231
break;
12261232
}
12271233
}
1228-
if (!foundEditNearSel) {
1229-
editsAreNearCursors = false;
1230-
break;
1231-
}
12321234
}
12331235

12341236
if (editsAreNearCursors) {

src/vs/monaco.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ declare namespace monaco.editor {
18841884
* @param cursorStateComputer A callback that can compute the resulting cursors state after the edit operations have been executed.
18851885
* @return The cursor state returned by the `cursorStateComputer`.
18861886
*/
1887-
pushEditOperations(beforeCursorState: Selection[], editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;
1887+
pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;
18881888
/**
18891889
* Change the end of line sequence. This is the preferred way of
18901890
* changing the eol sequence. This will land on the undo stack.

0 commit comments

Comments
 (0)