Opened 15 years ago
Closed 14 years ago
#12921 closed enhancement (wontfix)
Improve word count
Reported by: | shdus | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0 |
Component: | Editor | Keywords: | has-patch |
Focuses: | Cc: |
Description
The word count that displays below the textbox when you are writing a post does not change until you hit the enter key (usually). I think I have seem a few instances where it changed without hitting enter, but couldn't find any pattern. I don't know if this matters, but I am using Firefox 3.6.3.
Attachments (2)
Change History (12)
#2
in reply to:
↑ 1
@
14 years ago
- Resolution set to wontfix
- Status changed from new to closed
Replying to koopersmith:
You're right, it is for performance reasons and is the intended behaviour. Word count on large posts can be quite slow and interferes with the typing on slower computers if run constantly.
#3
@
14 years ago
- Cc koopersmith added
- Keywords has-patch added
- Resolution wontfix deleted
- Status changed from closed to reopened
- Summary changed from Word count does not change until you hit enter to Improve word count
- Type changed from defect (bug) to enhancement
Actually, I've been playing around with the code and wrote a patch that keeps performance about the same, but improves accuracy.
- When the wordcount function is blocked, it will estimate the wordcount by adding one to the current wordcount when the spacebar is pressed.
- It updates on paste in tinymce and html mode, and a user selection in html mode (tinymce doesn't have an onSelect event for some reason).
- It centralizes the functionality between tinymce and html mode by passing the functions into the wcWordCount object.
- It times the wc function, and if the execution time is high enough it will increase the timeout threshold accordingly. Currently it's 100ms * execution time, with the default timeout set to 2000ms. This might require some tweaking.
I thought about adding a few more features (like detecting when the user inserts a tag in html mode, and not incrementing), but that requires adding a keypress event. I think this is the best balance of performance and functionality.
#4
@
14 years ago
For those having trouble testing:
SCRIPT_DEBUG must be set to true, and for some reason wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js is loaded instead of editor_plugin.dev.js
12921.2.patch includes the compressed versions of editor_plugin.js and word-count.js so you only have to set SCRIPT_DEBUG to make it work.
#5
@
14 years ago
Running ed.getContent()
on each keyup is undesirable (line 165 in editor_plugin.dev.js in the patch). This triggers several large functions in TinyMCE and would interfere with typing in slower browsers. Would suggest testing in IE 6/7 with a 2,000 - 3,000 words post with many HTML tags.
#6
follow-up:
↓ 7
@
14 years ago
It's not—it's creating (not executing) an anonymous function that is only run in the wc function (word-count.dev.js line 54 in the patch). Haven't tested in IE yet, but I was testing on 80,000 word posts without any issues.
#7
in reply to:
↑ 6
@
14 years ago
Replying to koopersmith:
it's creating (not executing) an anonymous function...
It's creating a new function on every keyup? Typing a 2,000 words post X average of 5 keystrokes per word = 10,000 new lambda functions, starting to look like memory leak :)
A lot of testing went into making this plugin. It's a "nice to have" (secondary) feature so it shouldn't interfere with the main feature (typing) at all or it becomes pointless.
At first it used to update the word count every 10 sec but if the user was typing fast in a slower browser or on slower computer, sometimes there was a very annoying lag/skipping when it was running. The best time to update the count is when the user pauses typing for a moment. Nearly all users pause when starting a new paragraph or use the backspace key, so running the count then makes any lag virtually unnoticeable.
#8
@
14 years ago
- Milestone changed from Unassigned to 3.1
Setting to 3.1 to make it clear that this came in too late to be considered for 3.0.
Currently the word count updates on enter and the first key pressed after backspace or delete (that isn't backspace or delete). My guess is that this is for performance reasons. If not, it could be easily changed.