@@ -310,18 +310,6 @@ class PSDocumentFormattingEditProvider implements
310
310
return - 1 * editComparer ( left , right ) ;
311
311
} ) ;
312
312
313
- // We cannot handle multiple edits at the same point hence we
314
- // filter the markers so that there is only one edit per region
315
- if ( edits . length > 0 ) {
316
- uniqueEdits . push ( edits [ 0 ] ) ;
317
- for ( let edit of edits . slice ( 1 ) ) {
318
- let lastEdit : ScriptRegion = uniqueEdits [ uniqueEdits . length - 1 ] ;
319
- if ( lastEdit . startLineNumber !== edit . startLineNumber
320
- || ( edit . startColumnNumber + edit . text . length ) < lastEdit . startColumnNumber ) {
321
- uniqueEdits . push ( edit ) ;
322
- }
323
- }
324
- }
325
313
326
314
// we need to update the range as the edits might
327
315
// have changed the original layout
@@ -333,6 +321,22 @@ class PSDocumentFormattingEditProvider implements
333
321
// extend the range such that it starts at the first character of the
334
322
// start line of the range.
335
323
range = this . snapRangeToEdges ( range , document ) ;
324
+
325
+ // filter edits that are contained in the input range
326
+ edits = edits . filter ( edit => range . contains ( toRange ( edit ) . start ) ) ;
327
+ }
328
+
329
+ // We cannot handle multiple edits at the same point hence we
330
+ // filter the markers so that there is only one edit per region
331
+ if ( edits . length > 0 ) {
332
+ uniqueEdits . push ( edits [ 0 ] ) ;
333
+ for ( let edit of edits . slice ( 1 ) ) {
334
+ let lastEdit : ScriptRegion = uniqueEdits [ uniqueEdits . length - 1 ] ;
335
+ if ( lastEdit . startLineNumber !== edit . startLineNumber
336
+ || ( edit . startColumnNumber + edit . text . length ) < lastEdit . startColumnNumber ) {
337
+ uniqueEdits . push ( edit ) ;
338
+ }
339
+ }
336
340
}
337
341
338
342
// reset line difference to 0
@@ -341,7 +345,7 @@ class PSDocumentFormattingEditProvider implements
341
345
// we do not return a valid array because our text edits
342
346
// need to be executed in a particular order and it is
343
347
// easier if we perform the edits ourselves
344
- return this . applyEdit ( editor , uniqueEdits , range , 0 , index ) ;
348
+ return this . applyEdit ( editor , uniqueEdits , 0 , index ) ;
345
349
} )
346
350
. then ( ( ) => {
347
351
// execute the same rule again if we left out violations
@@ -361,7 +365,6 @@ class PSDocumentFormattingEditProvider implements
361
365
private applyEdit (
362
366
editor : TextEditor ,
363
367
edits : ScriptRegion [ ] ,
364
- range : Range ,
365
368
markerIndex : number ,
366
369
ruleIndex : number ) : Thenable < void > {
367
370
if ( markerIndex >= edits . length ) {
@@ -373,27 +376,22 @@ class PSDocumentFormattingEditProvider implements
373
376
let edit : ScriptRegion = edits [ markerIndex ] ;
374
377
let editRange : Range = toRange ( edit ) ;
375
378
376
- if ( range === null || range . contains ( editRange . start ) ) {
377
-
378
- // accumulate the changes in number of lines
379
- // get the difference between the number of lines in the replacement text and
380
- // that of the original text
381
- this . lineDiff += this . getNumLines ( edit . text ) - ( editRange . end . line - editRange . start . line + 1 ) ;
382
- return editor . edit ( ( editBuilder ) => {
383
- editBuilder . replace (
384
- editRange ,
385
- edit . text ) ;
386
- } ,
387
- {
388
- undoStopAfter : undoStopAfter ,
389
- undoStopBefore : undoStopBefore
390
- } ) . then ( ( isEditApplied ) => {
391
- return this . applyEdit ( editor , edits , range , markerIndex + 1 , ruleIndex ) ;
392
- } ) ; // TODO handle rejection
393
- }
394
- else {
395
- return this . applyEdit ( editor , edits , range , markerIndex + 1 , ruleIndex ) ;
396
- }
379
+
380
+ // accumulate the changes in number of lines
381
+ // get the difference between the number of lines in the replacement text and
382
+ // that of the original text
383
+ this . lineDiff += this . getNumLines ( edit . text ) - ( editRange . end . line - editRange . start . line + 1 ) ;
384
+ return editor . edit ( ( editBuilder ) => {
385
+ editBuilder . replace (
386
+ editRange ,
387
+ edit . text ) ;
388
+ } ,
389
+ {
390
+ undoStopAfter : undoStopAfter ,
391
+ undoStopBefore : undoStopBefore
392
+ } ) . then ( ( isEditApplied ) => {
393
+ return this . applyEdit ( editor , edits , markerIndex + 1 , ruleIndex ) ;
394
+ } ) ; // TODO handle rejection
397
395
}
398
396
399
397
private getNumLines ( text : string ) : number {
0 commit comments