@@ -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 ) {
0 commit comments