From ca8a183f38f9ed79c857181440d26b063d9cce19 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 13 Jun 2023 22:14:33 +1000 Subject: [PATCH] Add `WatchList.InsertRange` and use when duplicating rows in RAM Watch --- .../tools/Watch/WatchList/WatchList.cs | 15 +++++++++++++++ .../tools/Watch/RamWatch.cs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs index eb0c1212ee..ee418b0461 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs @@ -143,6 +143,21 @@ namespace BizHawk.Client.Common Changes = true; } + /// + /// 0 to prepend, to append, anything in-between to insert there + /// (the first elem of will end up at ) + /// + public void InsertRange(int index, IEnumerable collection) + { +#if NET6_0 + if (collection.TryGetNonEnumeratedCount(out var n) && n is 0) return; +#else + if (collection is ICollection hasCount && hasCount.Count is 0) return; +#endif + _watchList.InsertRange(index, collection); + Changes = true; + } + /// /// Removes item at the specified index /// diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 7be875bae6..77bc5fc2ef 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -411,7 +411,7 @@ namespace BizHawk.Client.EmuHawk { if (duplicate) { - _watches.AddRange(we.Watches); + _watches.InsertRange(WatchListView.SelectionEndIndex!.Value + 1, we.Watches); //TODO should be able to reduce the number of enumerations of selected rows if necessary --yoshi WatchListView.RowCount = _watches.Count; UpdateWatchCount(); }