Repository navigation
fix(content): colour the editor's length counter by the Length rule's own result - #1366
Conversation
… own result Follow-up to ansvisor#1357's review. The counter turned amber past the target while the Length rule passes within 20%. It now turns amber exactly when the Length rule is on and reads short or long (lengthWarns), so it can't disagree with the Rules tab: not with the rule turned off, and not with a rule value the counter's target clamps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk the follow-up to your #1357 review, item 1. The counter's colour now comes from the Length rule's own status (
Item 2 (the agent shortening instead of inserting) waits for the Shorten option. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good.
The counter's colour now comes from the Length rule's own status. It agrees with the Rules tab in every band: under min, inside the band including both edges (checkRule uses < and >), over max, and with the rule off. The colour follows the page about 400 ms behind the count, the same pace as the Rules tab.
Optional follow-up, not for this PR: the Rules tab takes any value from 0 to 999999 for Length (/^\d{1,6}$/ in _rules-tab.tsx). ruleLength clamps that value to 100–50,000, or falls back to the type's default for 0. checkRule uses the raw value.
- With a value of 0, the band is 0–0, so every page reads "long". The counter now shows amber against a "/ 3,000" target.
- Clamping the value where it is typed would make the counter and the rule always use the same number.
Summary
Follow-up to #1357's review: the Content Editor's character counter turns amber exactly when the Length rule reads short or long, not as soon as a page passes its target. So the counter and the Rules tab can't disagree.
Before:
Now the colour comes from the rule's own result, not a second check of the band.
lengthWarns(rules.rules)inlib/content/rules.tsis true when the Length rule is on and its status isbad(shortorlong). The editor passes it to the toolbar aslengthWarning. With the default 3,000 target, the counter is amber below 2,400 or above 3,600, in the same amber with itsdark:variant.A review pass caught two cases where a second band check in the toolbar would still have disagreed with the rule:
ruleLengthclamps the counter's target to that range, whilecheckRuleuses the raw value. With the colour read from the rule's status, the warning now follows the rule. The counter's "/ target" text still shows the clamped value.Not here: item 2 of that review (asking the Content Agent to shorten rather than insert when Length reads "over"). It belongs with the planned Shorten option.
Related issue
Follow-up to #1357 (review item 1). No issue.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Open a draft in the Content Editor whose type targets 3,000 characters:
rules.test.tscoverslengthWarns:Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) (0 errors; the 6 warnings are in untouched files, as on main)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run: web
yarn test(2,765 tests) andyarn build.🤖 Generated with Claude Code