Skip to content

Editor: Treat non-breaking and Unicode spaces as word separators in the word count. - #16199

Open
SainathPoojary wants to merge 1 commit into
WordPress:trunkfrom
SainathPoojary:fix/word-count-nbsp
Open

SainathPoojary wants to merge 1 commit into
WordPress:trunkfrom
SainathPoojary:fix/word-count-nbsp

Conversation

@SainathPoojary

@SainathPoojary SainathPoojary commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

The classic editor word count treats two words as one when they are separated by a no-break space (U+00A0) or another Unicode space. Only the   entity worked.

This adds those space characters to spaceRegExp in wp.utils.WordCounter, so they split words like a normal space. It also adds QUnit tests for them.

The same bug was fixed in the gutenberg: WordPress/gutenberg#87026

Testing

  1. Activate the Classic Editor plugin.

  2. Go to Posts > Add New and open the "Code" tab.

  3. Run this in the browser console:

    var t = top.document.getElementById( 'content' );
    t.value = 'one\u00A0two\u00A0three\u00A0four';
    t.dispatchEvent( new Event( 'input', { bubbles: true } ) );
  4. Wait a second and check "Word count".

Before: 1. After: 4.

Trac ticket: https://core.trac.wordpress.org/ticket/66797

Screenshot

Before

Screenshot 2026-11-24 at 4 27 09 PM

After

image

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Claude Code helped with the code changes. Review and testing the changes was done by me


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@SainathPoojary
SainathPoojary marked this pull request as ready for review November 24, 2026 11:55
@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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sainathpoojary.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants