Problem:
When I bold text in a card and then press Cmd+Z to undo, it keeps the bolding and undoes the previous edit instead.
Steps to reproduce:
- Open card editor
- Type some text
- Select text and press Cmd+B (or click bold button)
- Press Cmd+Z
- Expected: Bold formatting is removed
- Actual: Previous text edit is undone, bold remains
Technical Analysis:
This happens because Anki prevents the browser’s native Cmd+B and uses custom DOM manipulation instead. The browser’s undo system only tracks native
execCommand operations, not manual DOM changes.
Environment:
- Platform: MacOS 15.5 (24F74)
- Anki version: 25.02.5 (29192d15)
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
This seems like a development issue where the custom formatting system needs to integrate with browser undo.
GitHub Issue Draft (If developers triage from forum)
Bug: Bold formatting bypasses browser undo system
Description
Bold formatting (Cmd+B/Ctrl+B) creates <b> tags but doesn’t integrate with browser undo, causing Cmd+Z to skip formatting changes.
Root Cause
content-editable.ts:137-141prevents native Ctrl+B viapreventDefault()- Custom DOM manipulation in
surround/apply/format.tswraps text in<b>tags - Browser undo only tracks native
execCommandoperations, not manual DOM changes - Result: formatting operations are invisible to undo system
Expected Behavior
Cmd+Z should undo bold formatting applied via Cmd+B or bold button.
Current Behavior
Cmd+Z skips formatting and undoes previous text edits.
Affected Files
ts/editable/content-editable.ts- Prevents native shortcutsts/lib/domlib/surround/apply/format.ts- DOM manipulationts/editor/editor-toolbar/BoldButton.svelte- Bold implementationts/editor/surround.ts- Surrounder class
Solution Options
Preserve <b> tag behavior while adding undo integration via manual undo management or input event simulation.