Markdown toolbar buttons clear the textarea's native undo/redo history #107

Open
opened 2026-09-01 00:21:14 -04:00 by jared · 0 comments
Owner

Severity: Medium

assets/js/markdown.js (insertMarkdownFormat, insertMarkdownText, toolbarList, toolbarHeading, toolbarQuote, ~lines 360-503) all set textarea.value = ... directly. Assigning .value programmatically discards the browser's native undo stack (vs. document.execCommand('insertText', ...), which preserves it).

Repro: Type a paragraph, click Bold on a selection, then press Ctrl+Z — instead of undoing just the bold markup, the entire typed paragraph disappears (or undo does nothing further), because the whole prior undo history was wiped the moment the toolbar action ran.

Fix: Replace the direct .value = assignment in these toolbar handlers with document.execCommand('insertText', false, newText) (with a fallback to the current approach for browsers where execCommand is unavailable/deprecated) to preserve native undo/redo.

**Severity:** Medium `assets/js/markdown.js` (`insertMarkdownFormat`, `insertMarkdownText`, `toolbarList`, `toolbarHeading`, `toolbarQuote`, ~lines 360-503) all set `textarea.value = ...` directly. Assigning `.value` programmatically discards the browser's native undo stack (vs. `document.execCommand('insertText', ...)`, which preserves it). **Repro:** Type a paragraph, click Bold on a selection, then press Ctrl+Z — instead of undoing just the bold markup, the entire typed paragraph disappears (or undo does nothing further), because the whole prior undo history was wiped the moment the toolbar action ran. **Fix:** Replace the direct `.value =` assignment in these toolbar handlers with `document.execCommand('insertText', false, newText)` (with a fallback to the current approach for browsers where `execCommand` is unavailable/deprecated) to preserve native undo/redo.
jared added the priority/mediumux labels 2026-09-08 10:15:51 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/tinker_tickets#107