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

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.

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