From e77e1b63800fd76153d60c551c24919882fcfa19 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Thu, 28 Feb 2019 19:03:31 +0100 Subject: [PATCH] Fix listview not going to video position - thx OmrSi :) Fix #3430 --- src/Controls/SubtitleListView.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Controls/SubtitleListView.cs b/src/Controls/SubtitleListView.cs index 87439b541..b80b85c0e 100644 --- a/src/Controls/SubtitleListView.cs +++ b/src/Controls/SubtitleListView.cs @@ -1456,18 +1456,15 @@ namespace Nikse.SubtitleEdit.Controls selectedItem.Focused = true; var topIndex = topItem.Index; - int bottomIndex = topIndex + (Height - 30) / GetItemRect(0).Height; - if (index < topIndex || index > bottomIndex) + var numberOfVisibleItems = (Height - 30) / GetItemRect(0).Height; + int bottomIndex = topIndex + numberOfVisibleItems; + if (index >= bottomIndex) { - var nextScrollToIndex = index + (bottomIndex - topIndex) / 2; - if (nextScrollToIndex < Items.Count && nextScrollToIndex > 1) - { - Items[nextScrollToIndex].EnsureVisible(); - } - else - { - selectedItem.EnsureVisible(); - } + Items[Math.Min(Items.Count - 1, index + numberOfVisibleItems)].EnsureVisible(); + } + else if (index < topIndex) + { + Items[Math.Max(0, index - numberOfVisibleItems / 2)].EnsureVisible(); } EndUpdate(); }