Skip to content

fix: preserve block content when appending text at cursor#446

Merged
dcalhoun merged 3 commits intotrunkfrom
fix/at-mention-content-loss
Apr 9, 2026
Merged

fix: preserve block content when appending text at cursor#446
dcalhoun merged 3 commits intotrunkfrom
fix/at-mention-content-loss

Conversation

@dcalhoun
Copy link
Copy Markdown
Member

@dcalhoun dcalhoun commented Apr 9, 2026

What?

Revert the normalizeAttribute() call on block content in appendTextAtCursor, which was incorrectly discarding existing block text.

Why?

#429 introduced normalizeAttribute() to handle {raw, rendered} objects from the WordPress data store. It was also applied to block.attributes.content in appendTextAtCursor, but block attributes from getBlock() are RichTextData instances — not {raw, rendered} objects. Since RichTextData lacks a .raw property, normalizeAttribute() returned an empty string, discarding all existing block content before the insertion.

This caused @mentions (and any appendTextAtCursor usage) to lose existing block content. For example, typing @ in a paragraph and selecting a mention would replace the entire block content with just the username, dropping both the @ trigger and any preceding text.

Reported via WordPress-Android#22764.

How?

Reverted block.attributes.content handling in appendTextAtCursor to the original || '' fallback, which lets RichTextData objects pass through to create() where their toString() method correctly produces the HTML string.

normalizeAttribute() remains in place for entity record attributes (getEditedPostAttribute, getEditedPostContent) where {raw, rendered} objects are expected.

Testing Instructions

  1. Open the editor
  2. Focus a Rich Text block
  3. Type some content
  4. Type @
  5. Select a name from the list
  6. Verify the content is preserved and the name is inserted with a @ prefix
gbk-auto-complete.mov

dcalhoun and others added 2 commits April 9, 2026 12:42
Block attributes can be RichTextData objects (which have toString/valueOf
methods) rather than plain strings or {raw, rendered} objects.
normalizeAttribute incorrectly converts these to empty strings because
RichTextData lacks a .raw property, causing the existing block content
(e.g. a typed "@" trigger) to be lost when appendTextAtCursor rebuilds
the block.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
appendTextAtCursor passed block content through normalizeAttribute(),
which is designed for entity record attributes ({raw, rendered} objects).
Block attributes from getBlock() can be RichTextData objects, which lack
a .raw property. normalizeAttribute converted these to empty strings,
discarding the existing block content (e.g. "Hi, my block and @") before
inserting the appended text.

Revert to the original fallback (`|| ''`) which lets RichTextData pass
through to create(), where its toString() method correctly produces the
HTML string.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the [Type] Bug An existing feature does not function as intended label Apr 9, 2026
Present a simple picker with hardcoded suggestions when the @ or +
autocompleter triggers in the iOS and Android demo apps. This enables
manual testing of the appendTextAtCursor bridge method.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dcalhoun dcalhoun marked this pull request as ready for review April 9, 2026 17:04
@dcalhoun dcalhoun requested a review from jkmassel April 9, 2026 17:04
@dcalhoun dcalhoun merged commit 5b9bc98 into trunk Apr 9, 2026
17 checks passed
@dcalhoun dcalhoun deleted the fix/at-mention-content-loss branch April 9, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[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