WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#26620 closed defect (bug) (fixed)

Word Count is one number short

Reported by: jorbin Owned by: iseulde
Milestone: 4.3 Priority: normal
Severity: normal Version:
Component: Editor Keywords: needs-patch needs-refresh
Focuses: Cc:

Description

Write a post. The count will be one number too low in text view if you don't press enter.
For example:

This is some content. It should be ten words long.

The counter shows that being 9 words.

related: #6991

Attachments (4)

26620.diff (2.1 KB) - added by jorbin 7 years ago.
Unit Test
26620.2.diff (2.6 KB) - added by jorbin 7 years ago.
26620.3.diff (2.5 KB) - added by jorbin 7 years ago.
Screen Shot 2014-01-17 at 1.06.06 PM.png (14.1 KB) - added by wonderboymusic 7 years ago.
No Dice.

Download all attachments as: .zip

Change History (14)

@jorbin
7 years ago

Unit Test

#1 @SergeyBiryukov
7 years ago

  • Component changed from General to Editor

@jorbin
7 years ago

#2 follow-up: @jorbin
7 years ago

  • Keywords has-patch added

The above patch includes both a fix and a unit test.

I'm not sure if I am correctly checking for being in txt mode vs being in tinymce mode. Is there a better way to get this information?

#3 @SergeyBiryukov
7 years ago

  • Milestone changed from Awaiting Review to 3.9

#4 in reply to: ↑ 2 @nacin
7 years ago

Replying to jorbin:

I'm not sure if I am correctly checking for being in txt mode vs being in tinymce mode. Is there a better way to get this information?

Appears to be this: typeof tinyMCE != 'undefined' && ( ed = tinyMCE.activeEditor ) && !ed.isHidden() ) {

#5 @nacin
7 years ago

Two possible alternative fixes that are not editor-dependent:

  • Add a space to the end of tx prior to running the count.
  • Use /\S(\s+|$)/gm instead (untested).

#6 @nacin
7 years ago

Also, 26620.2.diff has JSHint errors. :-)

@jorbin
7 years ago

#7 @jorbin
7 years ago

Padding a space on to the end seemed simpler than changing the regex and works independent of the editor. New patch does that.

JSHint errors fixed.

#8 @mikeschroder
7 years ago

  • Keywords needs-patch needs-refresh added; has-patch removed
  • Milestone changed from 3.9 to Future Release

Due RC coming shortly, because this patch's tests don't cleanly apply and the current patch still seems to have the bug above, moving to future release.

#9 @iseulde
6 years ago

  • Owner set to iseulde
  • Resolution set to fixed
  • Status changed from new to closed

In 32856:

Editor: restructure word count

  • The WordCounter should only do one thing: count words. This makes it also easier to test.
  • Add some really basic unit tests.
  • Instead of only refreshing the count on enter and delete, refresh the count when the user stops typing. Also look at paste and content changes in TinyMCE.
  • Use match instead of replace when it is appropriate.
  • More readable code.

See #30966. Fixes #26620.

#10 @iseulde
6 years ago

  • Milestone changed from Future Release to 4.3
Note: See TracTickets for help on using tickets.