Skip to content

fix(content): colour the editor's length counter by the Length rule's own result - #1366

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/length-counter-band
Oct 22, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/length-counter-band

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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:

  • a 3,300-character page on a 3,000 target was amber while Length showed ✓;
  • a 2,000-character page was grey while Length read "under".

Now the colour comes from the rule's own result, not a second check of the band. lengthWarns(rules.rules) in lib/content/rules.ts is true when the Length rule is on and its status is bad (short or long). The editor passes it to the toolbar as lengthWarning. With the default 3,000 target, the counter is amber below 2,400 or above 3,600, in the same amber with its dark: variant.

A review pass caught two cases where a second band check in the toolbar would still have disagreed with the rule:

  • The Length rule turned off: the counter fell back to the type's default target and kept warning, even on an empty page, while the Rules tab said nothing. It now stays grey.
  • A rule value outside 100–50,000: ruleLength clamps the counter's target to that range, while checkRule uses 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Open a draft in the Content Editor whose type targets 3,000 characters:

  • at 3,300 characters, the counter stays grey and Rules › Length shows ✓;
  • at 2,000 or 3,700, it turns amber and Length reads "under" or "over".

rules.test.ts covers lengthWarns:

  • 3,300 on a 3,000 target doesn't warn;
  • 2,000 and 3,700 do;
  • with the rule off, an empty page doesn't.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) (0 errors; the 6 warnings are in untouched files, as on main)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run: web yarn test (2,765 tests) and yarn build.

🤖 Generated with Claude Code

… 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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk the follow-up to your #1357 review, item 1. The counter's colour now comes from the Length rule's own status (lengthWarns), not a second band check. So it can't disagree with the Rules tab:

  • not with the rule turned off, where it used to warn even on an empty page;
  • not with a rule value that ruleLength clamps for the counter.

Item 2 (the agent shortening instead of inserting) waits for the Shorten option.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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