Skip to content

SE UI drop video: find and offer matching subtitle - fix #11020#11038

Merged
niksedk merged 2 commits into
mainfrom
drag-drop-video-find-subtitle
May 18, 2026
Merged

SE UI drop video: find and offer matching subtitle - fix #11020#11038
niksedk merged 2 commits into
mainfrom
drag-drop-video-find-subtitle

Conversation

@niksedk
Copy link
Copy Markdown
Member

@niksedk niksedk commented May 18, 2026

Summary

  • Fixes the drag/drop asymmetry from SE 5 beta 28: Drag/drop asymmetry #11020: dropping a subtitle already opens its matching video, but dropping a video onto the video player did not load the matching subtitle.
  • After a dropped video opens, we now look for an associated subtitle file. If the editor is empty, we load it directly; otherwise we prompt (and the existing save-if-unsaved flow runs on confirmation).
  • Repairs FindSubtitleFileName, which was effectively broken: it called File.Exists with no directory, so it would only ever match files in the current working directory. It now searches the video's own folder, recurses into trimmed name variants (movie.enmovie, movie_enmovie), and finally scans for movie.<lang>.srt style names.

Test plan

  • Drop a video onto the video player with a matching subtitle (movie.mp4 + movie.srt) when the editor is empty — subtitle loads automatically.
  • Drop a video onto the video player with a matching subtitle when a subtitle is already loaded — user is prompted; on Yes, save-if-unsaved kicks in, then the subtitle loads.
  • Drop a video with a language-suffixed subtitle (movie.mp4 + movie.en.srt) — found and loaded.
  • Drop a video with no matching subtitle — no prompt, video opens normally.
  • Drop a subtitle on the window — still works as before (matching video is auto-loaded).
  • dotnet test tests/UI/UITests.csproj — 188/188 passing.

🤖 Generated with Claude Code

Dropping a subtitle on the window already opens its associated video,
but dropping a video on the video player did not load the matching
subtitle. Now it does: if no subtitle is loaded, load the found one;
otherwise prompt (and save-if-unsaved via the existing flow).

Also fixes FindSubtitleFileName, which was effectively broken — it
called File.Exists without the directory so it only ever matched files
in the current working directory. It now searches the video's own
directory, recurses into trimmed name variants (movie.en -> movie),
and falls back to scanning for movie.<lang>.srt style names.

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

Fixes the drag/drop asymmetry reported in #11020 by attempting to auto-locate and open a matching subtitle file after a video is dropped onto the video player, and by improving the underlying subtitle-file discovery logic to search in the video’s folder and handle common name variants.

Changes:

  • Enhanced subtitle lookup to search the video’s directory, try trimmed basename variants, and fall back to detecting {name}.{lang}.{ext} patterns (e.g. movie.en.srt).
  • Updated video drag/drop flow to optionally load an associated subtitle (auto-load when empty; prompt when a subtitle is already loaded).

Reviewed changes

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

File Description
src/ui/Logic/Media/FindSubtitleFileName.cs Reworks subtitle discovery to search alongside the video and support trimmed/language-suffixed naming patterns.
src/ui/Features/Main/MainViewModel.cs After opening a dropped video, attempts to find and (optionally) open an associated subtitle file.

Comment on lines +34 to +38
if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
{
try
{
foreach (var candidate in Directory.EnumerateFiles(directory, nameWithoutExtension + ".*"))
Comment on lines +49 to +52
catch
{
// ignore - directory not accessible
}
Comment thread src/ui/Features/Main/MainViewModel.cs Outdated
Comment on lines +17057 to +17075
if (!IsEmpty)
{
var answer = await MessageBox.Show(
Window!,
Se.Language.Title,
string.Format(Se.Language.Main.OpenSubtitleFileX, Path.GetFileName(foundSubtitleFileName)),
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (answer != MessageBoxResult.Yes)
{
return;
}

var doContinue = await HasChangesContinue();
if (!doContinue)
{
return;
}
}
- FindSubtitleFileName: treat empty Path.GetDirectoryName as "."
  so the fallback scan still runs for relative-path callers.
- FindSubtitleFileName: narrow the catch around Directory.EnumerateFiles
  to IOException / UnauthorizedAccessException / SecurityException /
  ArgumentException instead of swallowing everything.
- TryLoadAssociatedSubtitle: gate the prompt on !IsEmpty || !IsEmptyOriginal
  so the original-text column's unsaved edits aren't silently discarded
  (HasChangesContinue's ContinueNewOrExitOriginal step runs).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@niksedk niksedk merged commit 7d59b84 into main May 18, 2026
1 of 3 checks passed
@niksedk niksedk deleted the drag-drop-video-find-subtitle branch May 18, 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.

2 participants