[html] Pasting HTML code adds extra closing tag on first line (#228662)

This commit is contained in:
Martin Aeschlimann
2024-09-15 19:51:51 +02:00
committed by GitHub
parent 07bd3cfbf6
commit f0cdaab75f

View File

@@ -56,14 +56,20 @@ export function activateAutoInsertion(provider: (kind: 'autoQuote' | 'autoClose'
}
const lastChange = contentChanges[contentChanges.length - 1];
const lastCharacter = lastChange.text[lastChange.text.length - 1];
if (isEnabled['autoQuote'] && lastChange.rangeLength === 0 && lastCharacter === '=') {
doAutoInsert('autoQuote', document, lastChange);
} else if (isEnabled['autoClose'] && lastChange.rangeLength === 0 && (lastCharacter === '>' || lastCharacter === '/')) {
doAutoInsert('autoClose', document, lastChange);
if (lastChange.rangeLength === 0 && isSingleLine(lastChange.text)) {
const lastCharacter = lastChange.text[lastChange.text.length - 1];
if (isEnabled['autoQuote'] && lastCharacter === '=') {
doAutoInsert('autoQuote', document, lastChange);
} else if (isEnabled['autoClose'] && (lastCharacter === '>' || lastCharacter === '/')) {
doAutoInsert('autoClose', document, lastChange);
}
}
}
function isSingleLine(text: string): boolean {
return !/\n/.test(text);
}
function doAutoInsert(kind: 'autoQuote' | 'autoClose', document: TextDocument, lastChange: TextDocumentContentChangeEvent) {
const rangeStart = lastChange.range.start;
const version = document.version;