Skip to content

Commit

Permalink
[html] Pasting HTML code adds extra closing tag on first line (micros…
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli authored Sep 15, 2024
1 parent 07bd3cf commit f0cdaab
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions extensions/html-language-features/client/src/autoInsertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f0cdaab

Please sign in to comment.