OSDN Git Service

ScrollLockMode.Noneと判定されたタブのスクロール位置がタブ切替時に復元されない不具合を修正
authorKimura Youichi <kim.upsilon@bucyou.net>
Fri, 13 Jan 2023 19:24:48 +0000 (04:24 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Fri, 13 Jan 2023 19:28:19 +0000 (04:28 +0900)
Fixes: 20d6826b ("ListViewのスクロール位置・選択状態を保持するTimelineListViewStateを追加")

OpenTween/Resources/ChangeLog.txt
OpenTween/TimelineListViewState.cs
OpenTween/Tween.cs

index 3057b11..fb06c2f 100644 (file)
@@ -2,6 +2,7 @@
 
 ==== Unreleased
  * NEW: 引用ツイートを Ctrl+Shift+L で実行するショートカットを追加 (thx @WizardOfPSG!)
+ * FIX: 発言一覧のソート順が日付の昇順となっている場合にタブ切替時にスクロール位置が保持されない不具合を修正
 
 ==== Ver 3.0.0(2023/01/11)
  * OpenTween v3.0.0 からは .NET Framework 4.8 以上が必須になります
index 9b64d92..2a746f1 100644 (file)
@@ -82,14 +82,14 @@ namespace OpenTween
             this.savedSelectionState = this.SaveListViewSelection();
         }
 
-        public void Restore()
+        public void Restore(bool forceScroll = false)
         {
-            this.RestoreScroll();
+            this.RestoreScroll(forceScroll);
             this.RestoreSelection();
         }
 
-        public void RestoreScroll()
-            => this.RestoreListViewScroll(this.savedScrollState);
+        public void RestoreScroll(bool forceScroll = false)
+            => this.RestoreListViewScroll(this.savedScrollState, forceScroll);
 
         public void RestoreSelection()
             => this.RestoreListViewSelection(this.savedSelectionState);
@@ -102,8 +102,9 @@ namespace OpenTween
             var lockMode = this.GetScrollLockMode(lockScroll);
             long? topItemStatusId = null;
 
-            if (lockMode == ScrollLockMode.FixedToItem)
+            if (lockMode == ScrollLockMode.FixedToItem || lockMode == ScrollLockMode.None)
             {
+                // ScrollLockMode.None の場合も forceScroll = true の時に topItemStatusId を使用するため保存する
                 var topItemIndex = this.listView.TopItem?.Index ?? -1;
                 if (topItemIndex != -1 && topItemIndex < this.tab.AllCount)
                     topItemStatusId = this.tab.GetStatusIdAt(topItemIndex);
@@ -195,12 +196,16 @@ namespace OpenTween
         /// <summary>
         /// <see cref="SaveListViewScroll"/> によって保存されたスクロール位置を復元します
         /// </summary>
-        private void RestoreListViewScroll(ListViewScroll listScroll)
+        private void RestoreListViewScroll(ListViewScroll listScroll, bool forceScroll)
         {
             if (this.listView.VirtualListSize == 0)
                 return;
 
-            switch (listScroll.ScrollLockMode)
+            var scrollLockMode = listScroll.ScrollLockMode;
+            if (forceScroll && scrollLockMode == ScrollLockMode.None)
+                scrollLockMode = ScrollLockMode.FixedToItem;
+
+            switch (scrollLockMode)
             {
                 case ScrollLockMode.FixedToTop:
                     this.listView.EnsureVisible(0);
index 1108b32..8a844d2 100644 (file)
@@ -2783,7 +2783,7 @@ namespace OpenTween
 
             this.ListTab.Alignment = newAlignment;
 
-            currentListViewState.Restore();
+            currentListViewState.Restore(forceScroll: true);
         }
 
         private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
@@ -7909,7 +7909,7 @@ namespace OpenTween
             var listView = this.CurrentListView;
 
             var currentListViewState = this.listViewState[tab.TabName];
-            currentListViewState.Restore();
+            currentListViewState.Restore(forceScroll: true);
 
             if (this.Use2ColumnsMode)
             {