From cb37547390f7308203a53bd9797865776a803e08 Mon Sep 17 00:00:00 2001 From: Maruthan G Date: Thu, 9 Apr 2026 19:22:22 +0530 Subject: [PATCH] fix: clamp completion range for unclosed string literals When an attribute value has an unclosed quote, the replace range could extend past `<` characters after the cursor, causing completions to delete subsequent HTML tags. Clamp valueContentEnd to the cursor offset when the closing quote is missing. Fixes microsoft/vscode#273226 --- src/services/htmlCompletion.ts | 4 ++++ src/test/completion.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/services/htmlCompletion.ts b/src/services/htmlCompletion.ts index b6e8dfb..d6e899b 100644 --- a/src/services/htmlCompletion.ts +++ b/src/services/htmlCompletion.ts @@ -294,6 +294,10 @@ export class HTMLCompletion { // valueEnd points to the char after quote, which encloses the replace range if (valueEnd > valueStart && text[valueEnd - 1] === text[valueStart]) { valueContentEnd--; + } else { + // unclosed quote: clamp the end to the cursor position so that + // the replace range does not extend into subsequent HTML content + valueContentEnd = offset; } const wsBefore = getWordStart(text, offset, valueContentStart); diff --git a/src/test/completion.test.ts b/src/test/completion.test.ts index 8d4988b..fc7e2ab 100644 --- a/src/test/completion.test.ts +++ b/src/test/completion.test.ts @@ -164,6 +164,15 @@ suite('HTML Completion', () => { testCompletionFor('' }] + }); + testCompletionFor('' }] + }); + testCompletionFor('
', { items: [ { label: 'ltr', resultText: '
' },