From 3425ad740d9a545c15876db1f7eee1a03b3af61b Mon Sep 17 00:00:00 2001 From: MageByte-Zero Date: Mon, 11 May 2026 19:58:23 +0800 Subject: [PATCH] fix: prevent unstyled lines and theme corruption in inline edit mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pressing Enter in contenteditable inserts a
(Chrome default) that inherits no theme styles — new line renders plain. Pasting rich text injects foreign fonts/colors that break the presentation theme. Add three guards: defaultParagraphSeparator='br', Enter intercept that calls insertLineBreak, and paste handler that strips to plain text. Closes #49. --- html-template.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/html-template.md b/html-template.md index 384e1a10..801584e0 100644 --- a/html-template.md +++ b/html-template.md @@ -317,6 +317,38 @@ exportFile() { } ``` +### Inline Edit — Enter Key & Paste Fix + +When `contenteditable` is active on elements inside a themed `
` or `
`, pressing Enter inserts a `
` (Chrome default) instead of a `
`, which inherits none of the element's styles and makes the new line appear unstyled. Pasting rich text injects foreign fonts and colors that override the theme. + +Add these three guards to every inline-editing implementation: + +```javascript +// 1. Force
on Enter instead of
+document.execCommand('defaultParagraphSeparator', false, 'br'); + +// 2. Intercept Enter to prevent the browser default
insertion +document.addEventListener('keydown', e => { + if (e.key === 'Enter' && document.querySelector('[contenteditable]:focus')) { + e.preventDefault(); + document.execCommand('insertLineBreak'); + } +}); + +// 3. Strip rich-text formatting on paste — keep plain text only +document.addEventListener('paste', e => { + const active = document.activeElement; + if (!active?.isContentEditable) return; + e.preventDefault(); + const text = e.clipboardData.getData('text/plain'); + document.execCommand('insertText', false, text); +}); +``` + +Without these fixes: after pressing Enter, new lines render with no theme font or color (issue #49); pasting from a browser or document injects foreign styles that break the theme. + +--- + ## Image Pipeline (Skip If No Images) If user chose "No images" in Phase 1, skip this entirely. If images were provided, process them before generating HTML.