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
2 changes: 1 addition & 1 deletion src/parser/htmlScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class MultiLineStream {
}
const _BNG = '!'.charCodeAt(0);
const _MIN = '-'.charCodeAt(0);
const _LAN = '<'.charCodeAt(0);
export const _LAN = '<'.charCodeAt(0);
const _RAN = '>'.charCodeAt(0);
const _FSL = '/'.charCodeAt(0);
const _EQS = '='.charCodeAt(0);
Expand Down
16 changes: 14 additions & 2 deletions src/services/htmlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { HTMLDocument, Node } from '../parser/htmlParser.js';
import { createScanner } from '../parser/htmlScanner.js';
import { createScanner, _LAN } from '../parser/htmlScanner.js';
import {
CompletionConfiguration, ICompletionParticipant, ScannerState, TokenType, LanguageServiceOptions, DocumentContext,
Position, CompletionList, CompletionItemKind, Range, TextEdit, InsertTextFormat, CompletionItem, MarkupKind, TextDocument
Expand Down Expand Up @@ -293,7 +293,19 @@ export class HTMLCompletion {
let valueContentEnd = valueEnd;
// valueEnd points to the char after quote, which encloses the replace range
if (valueEnd > valueStart && text[valueEnd - 1] === text[valueStart]) {
valueContentEnd--;
// Even when a matching quote is found, the scanner may have latched
// onto an unrelated later quote across HTML tag boundaries. If any
// `<` appears between the cursor and the alleged closing quote,
// treat the value as unclosed and clamp so the completion cannot
// delete subsequent markup. See microsoft/vscode#273226.
let crossesTagBoundary = false;
for (let i = offset; i < valueEnd - 1; i++) {
if (text.charCodeAt(i) === _LAN) {
crossesTagBoundary = true;
break;
}
}
valueContentEnd = crossesTagBoundary ? offset : valueContentEnd - 1;
} else {
// unclosed quote: clamp the end to the cursor position so that
// the replace range does not extend into subsequent HTML content
Expand Down
12 changes: 12 additions & 0 deletions src/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ suite('HTML Completion', () => {
testCompletionFor('<th><input type="che|</th><td></td>', {
items: [{ label: 'checkbox', resultText: '<th><input type="checkbox</th><td></td>' }]
});
// unclosed quote with a stray quote later in the document (scanner would
// otherwise latch onto the stray quote and blow away the markup between
// the cursor and that quote). See microsoft/vscode#273226.
testCompletionFor('<th><input type="che|</th><p title="later"></p>', {
items: [{ label: 'checkbox', resultText: '<th><input type="checkbox</th><p title="later"></p>' }]
});
testCompletionFor('<th><input type="che|</th>\n<p title="later"></p>', {
items: [{ label: 'checkbox', resultText: '<th><input type="checkbox</th>\n<p title="later"></p>' }]
});
testCompletionFor('<th><input type="che|\n</th>', {
items: [{ label: 'checkbox', resultText: '<th><input type="checkbox\n</th>' }]
});

testCompletionFor('<div dir=|></div>', {
items: [
Expand Down
Loading