Skip to content

Commit a78b64f

Browse files
committed
update
1 parent 54818f3 commit a78b64f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

extensions/vscode/lib/rangeFormatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function getTrimmedNewText(
6666
let newEnd = edit.newText.length;
6767

6868
while (true) {
69-
if (oldTextIndex <= overlapStart) {
69+
if (oldTextIndex === overlapStart) {
7070
newStart = newTextIndex;
7171
}
7272
if (oldTextIndex === overlapEnd) {

extensions/vscode/tests/rangeFormatting.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ describe('provideDocumentRangeFormattingEdits', () => {
7575
const result = restrictFormattingEditsToRange(document, selection, edits, createTextEdit);
7676
expect(applyEdits(document, result)).toMatchInlineSnapshot(`"01X23456789"`);
7777
});
78+
79+
test('handles deletion where newText is shorter than oldText in selection', () => {
80+
const document = createDocument('ab ');
81+
const selection = createRange(1, 3);
82+
const edits = [createTextEdit(0, 4, 'ab')];
83+
const result = restrictFormattingEditsToRange(document, selection, edits, createTextEdit);
84+
expect(applyEdits(document, result)).toMatchInlineSnapshot(`"ab "`);
85+
});
7886
});
7987

8088
// self implementation of vscode test utils

0 commit comments

Comments
 (0)