Skip to content

Commit 84fcc34

Browse files
committed
Fix clicking TAStudio column header with non-contiguous rows selected
1 parent 758105f commit 84fcc34

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,36 @@ private void TasView_ColumnClick(object sender, InputRoll.ColumnClickEventArgs e
389389
if (ModifierKeys != Keys.Alt)
390390
{
391391
// nifty taseditor logic
392+
// your TAS Editor logic failed us (it didn't account for non-contiguous `SelectedRows`) --yoshi
392393
var selection = TasView.SelectedRows.ToArray(); // sorted asc, length >= 1
393-
bool allPressed = true;
394-
foreach (var index in selection)
394+
var allPressed = selection.All(index => CurrentTasMovie.BoolIsPressed(index, buttonName))
395+
&& selection[selection.Length - 1] != CurrentTasMovie.FrameCount; // last movie frame can't have input, but can be selected
396+
var iSelection = 0;
397+
var lastFrameIndexSeen = selection[iSelection] - 1;
398+
while (iSelection < selection.Length)
399+
{
400+
var index = selection[iSelection];
401+
if (index - lastFrameIndexSeen is not 1) break;
402+
lastFrameIndexSeen = index;
403+
iSelection++;
404+
}
405+
// `iSelection` now points to the element after the last of the first contiguous block--if the whole selection is contiguous, it's pointing after the end of the array...
406+
CurrentTasMovie.SetBoolStates(frame: selection[0], count: iSelection, buttonName, val: !allPressed);
407+
var blockStart = iSelection;
408+
lastFrameIndexSeen = selection[iSelection] - 1;
409+
while (iSelection < selection.Length) // ...and these will be equal, so the loop will end immediately
395410
{
396-
if (index == CurrentTasMovie.FrameCount // last movie frame can't have input, but can be selected
397-
|| !CurrentTasMovie.BoolIsPressed(index, buttonName))
411+
var index = selection[iSelection];
412+
if (index - lastFrameIndexSeen is not 1)
398413
{
399-
allPressed = false;
400-
break;
414+
// discontinuity; split off another block, and this is now the start of the next block
415+
CurrentTasMovie.SetBoolStates(frame: selection[blockStart], count: iSelection - blockStart, buttonName, val: !allPressed);
416+
blockStart = iSelection;
401417
}
418+
lastFrameIndexSeen = index;
419+
iSelection++;
402420
}
403-
CurrentTasMovie.SetBoolStates(frame: selection[0], count: selection.Length, buttonName, val: !allPressed);
421+
CurrentTasMovie.SetBoolStates(frame: selection[blockStart], count: iSelection - blockStart, buttonName, val: !allPressed); // `count` arg will be 0 if the whole selection is contiguous
404422
}
405423
else
406424
{

0 commit comments

Comments
 (0)