From a669dec3cf41a5768ce624dfd583af9c44690cba Mon Sep 17 00:00:00 2001 From: "Martijn van Berkel (Flitskikker)" Date: Sat, 10 Feb 2024 11:36:07 +0100 Subject: [PATCH] Fix seeking, hope to improve racing --- src/ui/Forms/Main.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index c0aa3b16c..63f33b52e 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -6612,6 +6612,14 @@ namespace Nikse.SubtitleEdit.Forms SubtitleListview1_SelectedIndexChanged(null, null); } + private void SelectListViewIndexAndEnsureVisible(Paragraph p) + { + SubtitleListview1.SelectedIndexChanged -= SubtitleListview1_SelectedIndexChanged; + SubtitleListview1.SelectIndexAndEnsureVisible(p); + SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged; + SubtitleListview1_SelectedIndexChanged(null, null); + } + private void FindPrevious() { if (_findHelper == null) @@ -21996,10 +22004,14 @@ namespace Nikse.SubtitleEdit.Forms controlSubtitle, (timeSeconds) => { - GoToTimeAndSelectPrecedingParagraph(timeSeconds); + // Invoke to not interfere with any inserting + BeginInvoke(new Action(() => { + GoToTimeAndSelectPrecedingParagraph(timeSeconds); + })); }, (newParagraph) => { + // Synchronous, so it's (hopefully) done before the next seek InsertAndSelectParagraph(newParagraph); } ); @@ -22019,7 +22031,7 @@ namespace Nikse.SubtitleEdit.Forms // Select correct paragraph for (int i = 0; i < _subtitle.Paragraphs.Count; i++) { - if (timeSeconds > _subtitle.Paragraphs[i].EndTime.TotalSeconds) + if (_subtitle.Paragraphs[i].EndTime.TotalSeconds > timeSeconds) { index = i - 1; SelectListViewIndexAndEnsureVisible(index); @@ -22075,7 +22087,7 @@ namespace Nikse.SubtitleEdit.Forms // Select it if needed if (selectInsertedParagraph) { - SubtitleListview1.SelectIndexAndEnsureVisible(paragraph); + SelectListViewIndexAndEnsureVisible(paragraph); } UpdateSourceView();