Skip to content

Fix undo shortcuts in text fields - #80542

Closed
scruffian wants to merge 1 commit into
trunkfrom
issue-80541
Closed

scruffian wants to merge 1 commit into
trunkfrom
issue-80541

Conversation

@scruffian

@scruffian scruffian commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #80541.

See #18755 and #38731.

This PR prevents editor-level undo/redo shortcuts from running when focus is inside an input or textarea.

Why?

Native form controls should keep their browser undo/redo behavior instead of triggering post editor history, which fixes the redesigned Custom HTML modal and related input/textarea cases.

How?

The editor undo/redo shortcut callbacks now return without calling editor history or preventDefault() when the keyboard event target is an input or textarea.

Testing Instructions

  1. Open a post or page.
  2. Insert a Custom HTML block.
  3. Open the HTML editor and type into the HTML, CSS, or JavaScript field.
  4. Press Cmd+Z or Ctrl+Z and confirm the focused text field undoes its own text change instead of undoing a block editor change.
  5. Confirm Cmd+Z or Ctrl+Z still undoes editor history when focus is not inside an input or textarea.

Testing Instructions for Keyboard

  1. Use the keyboard to focus the Custom HTML editor field.
  2. Type text, then press Cmd+Z or Ctrl+Z.
  3. Confirm the focused text field handles undo, and use Cmd+Shift+Z, Ctrl+Shift+Z, or Ctrl+Y to confirm redo behavior where supported by the browser and OS.

Screenshots or screencast

N/A.

Use of AI Tools

AI tooling used: OpenAI Codex assisted with implementation, tests, and PR preparation; changes were reviewed by the author.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jul 21, 2026
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: scruffian <scruffian@git.wordpress.org>
Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: sybrew <cybr@git.wordpress.org>
Co-authored-by: cbirdsong <cbirdsong@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Size Change: +10 B (0%)

Total Size: 7.75 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 501 kB +10 B (0%)

compressed-size-action

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Flaky tests detected in bba1cfe.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29953014845
📝 Reported issues:

@noruzzamans

Copy link
Copy Markdown
Contributor

Tested! confirms the fix works as expected. On trunk, pressing Cmd+Z inside the Custom HTML modal undid the block insertion and closed the whole modal. With this fix, Cmd+Z now undoes just the last text change within the field, and the modal stays open.

Screen.Recording.2026-07-22.at.8.15.19.AM.mov

@Mamaduka

Copy link
Copy Markdown
Member

This is not a singular issue - #80541 (comment).

Why are we not updating the attribute directly? Then, the editor history should work normally.

P.S. Utils like stopUndoRedoKeyboardShortcutPropagation probably don't need unit tests.

@scruffian
scruffian marked this pull request as draft July 22, 2026 19:53
@github-actions github-actions Bot added [Package] Editor /packages/editor and removed [Package] Block library /packages/block-library labels Jul 22, 2026
@scruffian scruffian changed the title Fix undo shortcuts in Custom HTML modal Fix undo shortcuts in text fields Jul 22, 2026
@scruffian
scruffian marked this pull request as ready for review July 22, 2026 20:09
@Mamaduka Mamaduka added [Feature] History History, undo, redo, revisions, autosave. [Type] Bug An existing feature does not function as intended labels Jul 23, 2026
@Mamaduka

Copy link
Copy Markdown
Member

Can there be a case when a consumer wants to use editor history with normal text fields?

cc @ellatrix, @youknowriad

@youknowriad
youknowriad requested a review from ellatrix July 23, 2026 09:28
@youknowriad

Copy link
Copy Markdown
Contributor

I think this is more complex than it seems. If the input/textarea is part of a block input (maybe the search block for instance), I think you'd want the regular block editor undo/redo no?

@Mamaduka

Copy link
Copy Markdown
Member

Related - #80768.

@scruffian

Copy link
Copy Markdown
Contributor Author

Closing in favour of #80768

@scruffian scruffian closed this Jul 28, 2026
@Mamaduka
Mamaduka deleted the issue-80541 branch July 29, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] History History, undo, redo, revisions, autosave. [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undo/redo doesn't work in the redesigned Custom HTML block

4 participants