# Bug Report: Undo (Cmd+Z) doesn't work with bold formatting

**URL:** <https://forums.ankiweb.net/t/bug-report-undo-cmd-z-doesnt-work-with-bold-formatting/64273>\
**Category:** Help\
**Created:** [July 20, 2025, 11:58pm UTC](https://forums.ankiweb.net/t/bug-report-undo-cmd-z-doesnt-work-with-bold-formatting/64273 "2025-07-20T23:58:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstack](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/cstack/32/29986_2.png) [@cstack](https://forums.ankiweb.net/u/cstack)\
**Post date:** [July 20, 2025, 11:58pm UTC](https://forums.ankiweb.net/t/bug-report-undo-cmd-z-doesnt-work-with-bold-formatting/64273/1 "2025-07-20T23:58:00Z")

</div>

**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:**

1. Open card editor
2. Type some text
3. Select text and press Cmd+B (or click bold button)
4. Press Cmd+Z
5. Expected: Bold formatting is removed
6. 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**

1. `content-editable.ts:137-141` prevents native Ctrl+B via `preventDefault()`
2. Custom DOM manipulation in `surround/apply/format.ts` wraps text in `<b>` tags
3. Browser undo only tracks native `execCommand` operations, not manual DOM changes
4. 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 shortcuts
- `ts/lib/domlib/surround/apply/format.ts` - DOM manipulation
- `ts/editor/editor-toolbar/BoldButton.svelte` - Bold implementation
- `ts/editor/surround.ts` - Surrounder class

**Solution Options**  
Preserve `<b>` tag behavior while adding undo integration via manual undo management or input event simulation.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [August 19, 2025, 11:58pm UTC](https://forums.ankiweb.net/t/bug-report-undo-cmd-z-doesnt-work-with-bold-formatting/64273/2 "2025-08-19T23:58:35Z")

</div>

Closed on August 19, 2025, 11:58pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
