Skip to content

Fix CPS strategy not updating grid until restart (#11379)#11387

Merged
niksedk merged 2 commits into
mainfrom
fix-cps-strategy-not-updating-grid
Jun 4, 2026
Merged

Fix CPS strategy not updating grid until restart (#11379)#11387
niksedk merged 2 commits into
mainfrom
fix-cps-strategy-not-updating-grid

Conversation

@niksedk
Copy link
Copy Markdown
Member

@niksedk niksedk commented Jun 4, 2026

Summary

Fixes #11379. Three related issues in the CPS/line-length pipeline:

  • CPS strategy change didn't repaint the grid. Changing the CPS strategy (or any other setting that feeds into CPS/length/colour calculations) and clicking OK updated Se.Settings and was synced into Configuration.Settings by ApplySettings/SetLibSeSettings, but the rows themselves never received PropertyChanged for the computed properties (CharactersPerSecond, the five *BackgroundBrushes, WordsPerMinute). Cells kept the previously-computed numbers until the user edited a row or restarted. ApplySettings now walks Subtitles and calls a small RefreshAfterSettingsChanged() helper on each row.

  • Two strategies in the dropdown silently fell back to CalcAll. CpsLineLengthStrategyDisplay.List() offered CalcIgnoreArabicDiacritics and CalcIgnoreArabicDiacriticsNoSpace, but CalcFactory.Calculators didn't include them, so the name lookup in MakeCalculator returned null and fell through to the ?? new CalcAll() default. Added both to the list.

  • Per-line length didn't agree with the total. The textbox info panel showed per-line lengths as raw line.Length and the total as cleanText.CountCharacters(false) (strategy-aware), so with any "no spaces" / "no punctuation" strategy the per-line sum didn't equal the displayed total. Same raw-.Length mismatch in the grid's TextBackgroundBrush for the row text-too-long check. Both now use line.CountCharacters(false), matching libse's other per-line length checks (SplitLongLinesHelper, FixLongLines, MoveWordUpDown, Helper.cs in FixCommonErrors).

Test plan

  • Open a subtitle, change CPS strategy in Options → CPS column repaints immediately (no restart needed).
  • Pick "CalcIgnoreArabicDiacritics" or "...NoSpace" — verify counts change (previously identical to CalcAll).
  • With a strategy that excludes spaces/punctuation, the per-line numbers under the textbox now sum to the displayed total.
  • With the same strategy, a line that is over SubtitleLineMaximumLength in raw chars but under it after stripping spaces no longer gets a red row.

🤖 Generated with Claude Code

Changing the CPS line-length strategy in Options had no visible effect:
the new value was stored in Se.Settings and synced to Configuration.Settings
by ApplySettings/SetLibSeSettings, but each row in the grid binds to computed
properties (CharactersPerSecond, *BackgroundBrush) that never received
PropertyChanged when the settings changed, so cells kept the previously-
computed numbers. Raise notifications on every row at the end of
ApplySettings.

Also:
- Add CalcIgnoreArabicDiacritics and CalcIgnoreArabicDiacriticsNoSpace to
  CalcFactory.Calculators - the settings dropdown offered them but the
  factory's name lookup fell through to CalcAll.
- Per-line length labels under the textbox and the grid row text-too-long
  colouring now use line.CountCharacters(false) instead of raw line.Length,
  matching libse's other per-line length checks (SplitLongLinesHelper,
  FixLongLines, MoveWordUpDown) and making the per-line counts agree with
  the strategy-aware total.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses CPS/line-length calculation consistency and UI refresh behavior in the subtitle grid and text info panel, ensuring that settings changes (notably CPS strategy) are reflected immediately without requiring edits or restart.

Changes:

  • Refreshes each subtitle row’s computed/bound properties after applying settings so CPS/WPM values and error highlighting repaint immediately.
  • Fixes missing CPS strategy implementations by registering the Arabic-diacritics calculators in CalcFactory.
  • Aligns per-line length display and “text too long” detection with the configured strategy-aware character counting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/ui/Features/Main/SubtitleLineViewModel.cs Uses strategy-aware per-line length checks for highlighting and adds a helper to raise property-change notifications after settings updates.
src/ui/Features/Main/MainViewModel.cs Triggers per-row refresh after ApplySettings() and updates per-line length display to use strategy-aware counting.
src/libse/Common/TextLengthCalculator/CalcFactory.cs Registers missing calculators so strategy selections don’t silently fall back to CalcAll.

Comment on lines 261 to 265

foreach (var line in stripped.SplitToLines())
{
if (line.Length > Se.Settings.General.SubtitleLineMaximumLength)
if (line.CountCharacters(false) > Se.Settings.General.SubtitleLineMaximumLength)
{
Comment on lines +518 to +525
OnPropertyChanged(nameof(CharactersPerSecond));
OnPropertyChanged(nameof(WordsPerMinute));
OnPropertyChanged(nameof(TextBackgroundBrush));
OnPropertyChanged(nameof(DurationBackgroundBrush));
OnPropertyChanged(nameof(CpsBackgroundBrush));
OnPropertyChanged(nameof(WpmBackgroundBrush));
OnPropertyChanged(nameof(GapBackgroundBrush));
}
Address Copilot review on PR #11387: PixelWidth depends on
ShowColumnPixelWidth, ColorTextTooWide, and the font name/size used by
CalculatePixelWidth, so it must also be re-notified when settings
change. Otherwise the Pixel Width column stays stale until the row
text changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@niksedk niksedk merged commit c03b06c into main Jun 4, 2026
1 of 3 checks passed
@niksedk niksedk deleted the fix-cps-strategy-not-updating-grid branch June 4, 2026 12:13
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.

[SE5 RC2] inconsistent cps counting and error flagging issues

2 participants