Skip to content

Suggest mode: Reject type-over overlapping a suggestion marker - #80229

Open
i-am-chitti wants to merge 1 commit into
WordPress:suggest/inlinefrom
i-am-chitti:fix/79799-suggestion-overlap-clean-reject
Open

i-am-chitti wants to merge 1 commit into
WordPress:suggest/inlinefrom
i-am-chitti:fix/79799-suggestion-overlap-clean-reject

Conversation

@i-am-chitti

Copy link
Copy Markdown
Contributor

What?

In Suggesting mode, typing over a selection that overlaps an existing inline suggestion marker now cleanly rejects the keystroke (with a snackbar explaining why) instead of falling through to native editing, which corrupted the content.

Part of #73411. Fixes #79799.

Why?

The addition/deletion keyboards intentionally decline to build a suggestion when the current selection overlaps an existing marker (wrapping the range in a del would re-attribute part of that marker to a new id). The problem was how the addition keyboard declined: it returned without cancelling the event, so the browser edited a DOM that still contained the <mark class="wp-suggestion">. That native surgery corrupted the content:

  • the typed leading space was dropped,
  • the marker was fragmented into several <mark> segments, and
  • the paragraph occasionally emptied entirely.

This is the pre-existing behaviour documented in #79799 (not a regression from the readEventRange DOM-caret work in #79714 / #79752).

How?

  • suggestion-addition-keyboard.js: insertText now returns a tri-state — INSERT_HANDLED (wrote a suggestion), INSERT_REJECTED (deliberately declined but must still cancel native editing), INSERT_DEFERRED (no valid inline anchor — let it fall through). The onBeforeInput / onPaste handlers preventDefault on HANDLED and REJECTED, and only fall through for DEFERRED. The type-over-overlap guard returns REJECTED, so the browser never touches the marker DOM.
  • A snackbar ("You can't type over an existing suggestion. Accept or reject it first.") is shown on reject — with a stable notice id so a burst of keystrokes refreshes one notice instead of stacking — so the swallowed keystroke doesn't read as an unresponsive editor.
  • Building a well-formed combined deletion+addition suggestion for this case is left to a follow-up phase; this PR guarantees the "cleanly rejected, no content change" outcome from the issue.

Why the deletion/cut guards are left unchanged

They share the same structural shape, but their fall-through is already captured cleanly as a whole-attribute suggestion (the reconciler + store interceptor), pinned by the existing e2e test "seam: a delete straddling an existing marker never corrupts it". Rejecting them would remove that working behaviour, so this PR scopes to the addition type-over that actually corrupts.

Testing Instructions

  1. Enable the Suggestion Mode experiment (Gutenberg → Experiments).
  2. Add a paragraph Hello world and switch the editor mode to Suggesting.
  3. Select world and press Ctrl/Cmd+B — world gets wrapped in a format suggestion marker.
  4. With world still selected (do not collapse the caret), type more.

Expected: nothing is inserted, the paragraph still reads Hello world, the world marker stays a single intact <mark> (no dropped space, no fragmented markers, block not emptied), and a snackbar explains why the keystroke did nothing.

Automated: test/e2e/specs/editor/various/suggestion-mode-overlay-retirement.spec.js adds a regression test ("type-over of a selection overlapping a marker is rejected, not corrupted"). Whole spec passes locally (9/9), including the delete-straddle test that proves no regression.

Screenshots or screencast

Before -
Image

After -
image

Usage of AI

Claude Code - Opus 4.8

@github-actions github-actions Bot added the [Package] Editor /packages/editor label Jul 14, 2026
@github-actions

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: i-am-chitti <iamchitti@git.wordpress.org>

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[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.

2 participants