Skip to content

Add Unbreak / Auto-break / Split-rebalance / Evenly distribute to Selected Lines menu#11400

Merged
niksedk merged 2 commits into
mainfrom
add-selected-lines-context-menu-entries
Jun 4, 2026
Merged

Add Unbreak / Auto-break / Split-rebalance / Evenly distribute to Selected Lines menu#11400
niksedk merged 2 commits into
mainfrom
add-selected-lines-context-menu-entries

Conversation

@niksedk
Copy link
Copy Markdown
Member

@niksedk niksedk commented Jun 4, 2026

Summary

Four line-shaping operations were missing from SubtitleGrid → Selected Lines in the context menu. This PR wires the existing Unbreak and AutoBreak commands into the submenu, adds a "Split/rebalance long lines…" entry that opens the existing Tools dialog scoped to the selected lines, and ports SE4's "Evenly distribute lines" as a new command.

Changes

Unbreak / Auto-break (one-line additions)

The view-model methods already exist (MainViewModel.cs:10704 / 10721) and iterate SubtitleGrid.SelectedItems. Just added menu entries bound to UnbreakCommand / AutoBreakCommand. Reuses Se.Language.General.Unbreak and Se.Language.General.AutoBreak (which already exist in every translation).

Split/rebalance long lines (new — opens existing dialog scoped to selection)

ShowToolsSplitBreakLongLinesSelectedLinesCommand:

  1. Snapshots the lowest selected index.
  2. Opens the existing SplitBreakLongLinesWindow with only the selected SubtitleLineViewModels.
  3. On OK, removes the selected lines from Subtitles and splices the dialog's AllSubtitlesFixed result in at the lowest selected index.

Non-contiguous selections are compacted together at that index. The existing full-subtitle entry under Tools menu is unchanged. Reuses Se.Language.Main.Menu.SplitBreakLongLines.

Evenly distribute lines (by CPS) — new, ported from SE4

EvenlyDistributeSelectedLinesCommand ports Forms/Main.cs:22773-22822 from se4-legacy. Algorithm:

  • Take the time span from the first selected paragraph's start to the last selected paragraph's end.
  • Subtract (SelectedCount - 1) × MinimumBetweenLines.
  • Distribute the remaining duration proportionally to each paragraph's CountCharacters(true) (CPS-equalizing redistribution).
  • Pack back-to-back with the configured minimum gap.

Only visible when more than one line is selected (HasMultipleLinesSelected binding). New language strings:

  • Main.Menu.EvenlyDistributeLines = "Evenly distribute lines (by CPS)"
  • Main.NumberOfLinesEvenlyDistributedX = "Evenly distributed {0} lines" (status message)

Menu structure

The four new entries are wrapped in Separators to keep line-shaping operations together and away from the unrelated entries above and below:

Selected lines >
  Speech to Text
  Text to Speech
  Auto Translate
  Change Casing
  Set Layer
  Fix common errors
  Multiple replace
  ─────────
  Unbreak text                ← new
  Auto-break text             ← new
  Split/rebalance long lines… ← new (opens dialog scoped to selection)
  Evenly distribute lines (by CPS) ← new
  ─────────
  Fill with clipboard
  Surround with 1/2/3
  Cut video
  Statistics

Test plan

  • Select several lines, right-click → Selected Lines → Unbreak text. Confirm only the selected lines have line breaks removed.
  • Same with Auto-break text.
  • Select a few lines with one long line. Open Split/rebalance long lines… from the context menu. Confirm the dialog opens populated with only the selected lines; on OK the result replaces just those lines.
  • Non-contiguous selection + Split/rebalance: the result still gets spliced in at the lowest selected index (the other selected items elsewhere in the grid are pulled together at that position).
  • Select two adjacent lines (one short, one long). Evenly distribute lines (by CPS). The long line should get more time than the short one, both packed back-to-back with the configured min gap.
  • Single-line selection: Evenly distribute is hidden.
  • Confirm the existing Tools → Split/rebalance long lines… still operates on the full subtitle.
  • Build clean; libse tests pass (367/367); UI tests pass (306/306).

🤖 Generated with Claude Code

niksedk and others added 2 commits June 4, 2026 21:26
…ed Lines menu

Four line-shaping operations were missing from the SubtitleGrid >
Selected Lines context submenu:

* Unbreak — wires existing UnbreakCommand to a menu entry. Reuses
  Se.Language.General.Unbreak ("Unbreak text").
* Auto-break — wires existing AutoBreakCommand. Reuses
  Se.Language.General.AutoBreak ("Auto-break text").
* Split/rebalance long lines — new
  ShowToolsSplitBreakLongLinesSelectedLinesCommand opens the existing
  SplitBreakLongLines dialog scoped to the current selection. On OK,
  the selected items are removed from Subtitles and the dialog's
  AllSubtitlesFixed result is spliced in at the lowest selected index.
  Non-contiguous selections are compacted together at that index.
  Reuses Se.Language.Main.Menu.SplitBreakLongLines.
* Evenly distribute lines (by CPS) — new
  EvenlyDistributeSelectedLinesCommand ports the SE4 algorithm
  (Forms/Main.cs:22773-22822). The span from the first selected
  paragraph's start to the last selected paragraph's end is split
  proportionally to each paragraph's character count (CPS-equalizing
  redistribution), packing the result back-to-back with the configured
  minimum gap between lines. Visible only when more than one line is
  selected (HasMultipleLinesSelected binding). New strings:
  Main.Menu.EvenlyDistributeLines and the status string
  Main.NumberOfLinesEvenlyDistributedX.

Menu group is separated above and below by horizontal dividers to keep
the line-shaping operations together and away from the unrelated
entries.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two issues:

1. Pre-existing bug in SplitBreakLongLinesViewModel.UpdatePreview:
   the rebalance pass computed `rebalancedText` but never assigned it
   back to `item.Text`, so the dialog reported "X lines rebalanced" but
   the AllSubtitlesFixed output kept the original text. The bug
   affected the existing Tools menu entry too — only the split path
   actually mutated text. Add the missing `item.Text = rebalancedText`
   inside the change-detected branch.

2. ShowToolsSplitBreakLongLinesSelectedLines used Remove+Insert in a
   loop to splice the dialog result back into Subtitles. Switch to the
   standard Clear+AddRange pattern used everywhere else in this file:
   rebuild Subtitles by walking the original list in order, replacing
   the run of selected items with the dialog's AllSubtitlesFixed at
   the position of the first selected item, then Clear+AddRange. Same
   behavior for the common contiguous-selection case, but matches the
   project convention and avoids per-item ObservableCollection churn.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@niksedk niksedk merged commit ea5abb6 into main Jun 4, 2026
1 of 3 checks passed
@niksedk niksedk deleted the add-selected-lines-context-menu-entries branch June 4, 2026 19:37
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.

1 participant