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