Skip to content

Fix #13682: column paste anchors on the first selected row - #13685

Merged
niksedk merged 1 commit into
mainfrom
claude/subtitleedit-issue-13682-133b11
Aug 16, 2026
Merged

Fix #13682: column paste anchors on the first selected row#13685
niksedk merged 1 commit into
mainfrom
claude/subtitleedit-issue-13682-133b11

Conversation

@niksedk

@niksedk niksedk commented Aug 16, 2026

Copy link
Copy Markdown
Member

Problem

Part 2 of #13682: Column > Paste from clipboard > Replace existing cells works when the rows are selected bottom-to-top, but pastes at the wrong place when the same rows are selected top-to-bottom.

ColumnPasteFromClipboard anchored on Subtitles.IndexOf(SelectedSubtitle). SelectedSubtitle is the moving end of a shift- or drag-selection — SelectGridRange deliberately selects currentIndex first so the edit box and waveform follow the row the user stopped on. So:

  • picked bottom-to-top → current row is the top of the selection → anchor correct, paste works;
  • picked top-to-bottom → current row is the bottom of the selection → the paste starts there and writes over the lines below the selection instead of over the selection itself.

SE4 used int index = FirstSelectedIndex; (4.0.16:src/ui/Forms/Main.cs:33434), which is direction-independent.

Fix

New MainViewModel.FirstSelectedSubtitleIndex — the topmost selected row, display-only reference rows excluded, -1 when nothing editable is selected. It is SE4's FirstSelectedIndex, built on the already-ordered SubtitleGridSelectedItems.

Both column commands that write downwards from the selection now use it:

  • ColumnPasteFromClipboard
  • ColumnInsertTextFromSubtitle — same defect, and SE4 anchored it on FirstSelectedIndex too (4.0.16:src/ui/Forms/Main.cs:33726)

The SelectedSubtitle == null guards are gone: the existing idx < 0 check already covers that, and it now also covers a selection consisting only of display-only reference rows, which the old guard let through.

Verification

  • New theory in SubtitleGridSelectionOrderTests shift-clicks in both directions through the real headless grid and asserts the anchor is the first selected row while the current row stays the row the user stopped on
  • RED check: with the anchor reverted to SelectedSubtitle, the downward case fails and the upward case passes — exactly the asymmetry reported in the issue
  • dotnet build src/ui/UI.csproj — 0 warnings, 0 errors
  • dotnet test tests/UI/UITests.csproj — 2809 passed, 0 failed

Two earlier full-suite runs each had one failure (WebVttStylePickerViewModelTests.CheckedStylesApplyAsCueClassesOnTheLine on the first), green in isolation and on re-run — the known parallel/shared-settings flake, unrelated to this code.

Scope

This fixes only part 2 of #13682. Part 1 (restoring SE4's direct Ctrl+V overwrite of the selected lines) is untouched and needs its own change in SubtitleGridCopyPasteHelper.Paste — which is also what open PR #13262 edits.

Not addressed here either: the column paste silently truncates when the clipboard has more lines than there are rows below the anchor.

🤖 Generated with Claude Code

"Column > Paste from clipboard" and "Column > Insert text from
subtitle" anchored on SelectedSubtitle, which is the moving end of a
shift- or drag-selection (SelectGridRange deliberately makes the row
the user stopped on the current one, so the edit box follows them).

Selecting rows bottom-to-top therefore anchored on the top row and
worked, while selecting the same rows top-to-bottom anchored on the
bottom row: the paste started there and wrote over the lines below
the selection instead of over the selection itself.

Both commands now start at the topmost selected row - SE4's
FirstSelectedIndex, which both of these code paths used.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@niksedk
niksedk merged commit db6e719 into main Aug 16, 2026
1 check passed
@niksedk
niksedk deleted the claude/subtitleedit-issue-13682-133b11 branch August 16, 2026 05:02
@niksedk niksedk mentioned this pull request Aug 16, 2026
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