fix(studio): format inserted block HTML with proper indentation

insertTimelineAssetIntoSource now detects the parent indent level and
adds the new element with matching child indentation. Block attributes
are written one-per-line for readability.
This commit is contained in:
Miguel Ángel
2026-05-21 18:28:17 -04:00
parent 997e3948e4
commit 6f9b655fff
2 changed files with 20 additions and 10 deletions
@@ -126,5 +126,12 @@ export function insertTimelineAssetIntoSource(source: string, assetHtml: string)
throw new Error("No composition root found in target source");
}
const insertAt = match.index + match[0].length;
return `${source.slice(0, insertAt)}${assetHtml}${source.slice(insertAt)}`;
const lineStart = source.lastIndexOf("\n", match.index);
const leadingWhitespace = source.slice(lineStart + 1, match.index).match(/^(\s*)/)?.[1] ?? "";
const childIndent = leadingWhitespace + " ";
const indented = assetHtml
.split("\n")
.map((line, i) => (i === 0 ? line : childIndent + line))
.join("\n");
return `${source.slice(0, insertAt)}\n${childIndent}${indented}${source.slice(insertAt)}`;
}