Skip to content

Commit 776b0ca

Browse files
committed
fix(html): pasting HTML code adds extra closing tag on first line
Refs: microsoft/vscode#228662
1 parent 54e88da commit 776b0ca

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

packages/html/index.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ export function create({
116116
};
117117
useDefaultDataProvider?: boolean;
118118
isFormattingEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
119-
isAutoCreateQuotesEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
120-
isAutoClosingTagsEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
121119
getDocumentContext?(context: LanguageServiceContext): html.DocumentContext;
122120
getFormattingOptions?(document: TextDocument, options: FormattingOptions, context: LanguageServiceContext): ProviderResult<html.HTMLFormatConfiguration>;
123121
getCompletionConfiguration?(document: TextDocument, context: LanguageServiceContext): ProviderResult<html.CompletionConfiguration | undefined>;
@@ -370,36 +368,26 @@ export function create({
370368
});
371369
},
372370

373-
async provideAutoInsertSnippet(document, selection, change) {
371+
async provideAutoInsertSnippet(document, selection, lastChange) {
374372
// selection must at end of change
375-
if (document.offsetAt(selection) !== change.rangeOffset + change.text.length) {
373+
if (document.offsetAt(selection) !== lastChange.rangeOffset + lastChange.text.length) {
376374
return;
377375
}
378376
return worker(document, async htmlDocument => {
379-
if (change.rangeLength === 0 && change.text.endsWith('=')) {
380-
381-
const enabled = await context.env.getConfiguration?.(configurationSections.autoCreateQuotes) ?? true;
382-
383-
if (enabled) {
384-
385-
const completionConfiguration = await getCompletionConfiguration(document, context);
386-
const text = htmlLs.doQuoteComplete(document, selection, htmlDocument, completionConfiguration);
387-
388-
if (text) {
389-
return text;
377+
if (lastChange.rangeLength === 0 && !/\n/.test(lastChange.text)) {
378+
if (lastChange.text.endsWith('=')) {
379+
const enabled = await context.env.getConfiguration?.(configurationSections.autoCreateQuotes) ?? true;
380+
if (enabled) {
381+
const completionConfiguration = await getCompletionConfiguration(document, context);
382+
const text = htmlLs.doQuoteComplete(document, selection, htmlDocument, completionConfiguration);
383+
return text ?? undefined;
390384
}
391385
}
392-
}
393-
if (change.rangeLength === 0 && (change.text.endsWith('>') || change.text.endsWith('/'))) {
394-
395-
const enabled = await context.env.getConfiguration?.(configurationSections.autoClosingTags) ?? true;
396-
397-
if (enabled) {
398-
399-
const text = htmlLs.doTagComplete(document, selection, htmlDocument);
400-
401-
if (text) {
402-
return text;
386+
if (lastChange.text.endsWith('>') || lastChange.text.endsWith('/')) {
387+
const enabled = await context.env.getConfiguration?.(configurationSections.autoClosingTags) ?? true;
388+
if (enabled) {
389+
const text = htmlLs.doTagComplete(document, selection, htmlDocument);
390+
return text ?? undefined;
403391
}
404392
}
405393
}

0 commit comments

Comments
 (0)