Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/services/htmlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ suite('HTML Completion', () => {
testCompletionFor('<input src="c" type=color| ', {
items: [{ label: 'color', resultText: '<input src="c" type="color" ' }]
});

// unclosed string literals should not extend the replace range past the cursor
testCompletionFor('<th><input type="che|</th>', {
items: [{ label: 'checkbox', resultText: '<th><input type="checkbox</th>' }]
});
testCompletionFor('<th><input type="che|</th><td></td>', {
items: [{ label: 'checkbox', resultText: '<th><input type="checkbox</th><td></td>' }]
});

testCompletionFor('<div dir=|></div>', {
items: [
{ label: 'ltr', resultText: '<div dir="ltr"></div>' },
Expand Down
Loading