Document intentional native element creation

This commit is contained in:
murashit 2026-07-10 16:39:29 +09:00
parent 3845da80e0
commit dec80ff6cf
3 changed files with 4 additions and 0 deletions

View file

@ -39,6 +39,7 @@ export class ThreadStreamMarkdownRenderer {
const sourcePath = this.options.app.workspace.getActiveFile()?.path ?? "";
const generation = (this.renderGenerations.get(parent) ?? 0) + 1;
this.renderGenerations.set(parent, generation);
// eslint-disable-next-line obsidianmd/prefer-create-el -- This detached staging node must belong to the parent's document.
const staging = parent.ownerDocument.createElement("div");
void MarkdownRenderer.render(this.options.app, text, staging, sourcePath, this.options.owner).then(() => {
if (!parent.isConnected || this.renderGenerations.get(parent) !== generation) return;

View file

@ -41,6 +41,7 @@ function textareaHeightMirror(doc: Document): HTMLTextAreaElement {
const existing = textareaHeightMirrors.get(doc);
if (existing?.isConnected) return existing;
const staleMirrors = [...doc.querySelectorAll<HTMLTextAreaElement>(`.${TEXTAREA_HEIGHT_MIRROR_CLASS}`)];
// eslint-disable-next-line obsidianmd/prefer-create-el -- This detached mirror must belong to the measured textarea's document.
const mirror = staleMirrors.shift() ?? doc.createElement("textarea");
for (const duplicate of staleMirrors) duplicate.remove();
mirror.tabIndex = -1;

View file

@ -63,6 +63,7 @@ function textareaCaretTop(textarea: HTMLTextAreaElement, position: number): numb
if (!window) return null;
const style = window.getComputedStyle(textarea);
// eslint-disable-next-line obsidianmd/prefer-create-el -- This detached mirror must belong to the measured textarea's document.
const mirror = document.createElement("div");
for (const property of textareaMirrorStyleProperties) {
mirror.style[property] = style[property];
@ -75,6 +76,7 @@ function textareaCaretTop(textarea: HTMLTextAreaElement, position: number): numb
};
mirror.setCssProps(mirrorProps);
// eslint-disable-next-line obsidianmd/prefer-create-el -- This detached marker must belong to the mirror's document.
const marker = document.createElement("span");
marker.textContent = "\u200b";
mirror.append(document.createTextNode(textarea.value.slice(0, position)), marker);