@@ -310,18 +310,6 @@ class PSDocumentFormattingEditProvider implements
310310 return - 1 * editComparer ( left , right ) ;
311311 } ) ;
312312
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- }
325313
326314 // we need to update the range as the edits might
327315 // have changed the original layout
@@ -333,6 +321,22 @@ class PSDocumentFormattingEditProvider implements
333321 // extend the range such that it starts at the first character of the
334322 // start line of the range.
335323 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+ }
336340 }
337341
338342 // reset line difference to 0
0 commit comments