Prevent insertion of breaks into empty fields

to allow :empty CSS selector to also work on fields other than the first one.
This commit is contained in:
Matthias Metelka 2022-06-15 01:55:36 +02:00
parent 47d6cd3fac
commit 1615fd5cf4

View file

@ -17,19 +17,12 @@ function adjustInputHTML(html: string): string {
return html; return html;
} }
function adjustInputFragment(fragment: DocumentFragment): void {
if (nodeContainsInlineContent(fragment)) {
fragment.appendChild(document.createElement("br"));
}
}
export function storedToFragment(storedHTML: string): DocumentFragment { export function storedToFragment(storedHTML: string): DocumentFragment {
/* We need .createContextualFragment so that customElements are initialized */ /* We need .createContextualFragment so that customElements are initialized */
const fragment = document const fragment = document
.createRange() .createRange()
.createContextualFragment(createDummyDoc(adjustInputHTML(storedHTML))); .createContextualFragment(createDummyDoc(adjustInputHTML(storedHTML)));
adjustInputFragment(fragment);
return fragment; return fragment;
} }