Skip to content

Commit fb397a4

Browse files
committed
Fix clicking TAStudio column header with non-contiguous rows selected
1 parent ce3075d commit fb397a4

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

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

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,69 @@ private void TasView_ColumnClick(object sender, InputRoll.ColumnClickEventArgs e
390390
if (ModifierKeys != Keys.Alt)
391391
{
392392
// nifty taseditor logic
393+
// your TAS Editor logic failed us (it didn't account for non-contiguous `SelectedRows`) --yoshi
393394
var selection = TasView.SelectedRows.ToArray(); // sorted asc, length >= 1
394395
bool allPressed = true;
395-
foreach (var index in selection)
396+
var contiguous = true;
397+
var iSelection = 0;
398+
var lastFrameIndexSeen = selection[iSelection] - 1;
399+
while (iSelection < selection.Length)
396400
{
401+
var index = selection[iSelection];
402+
if (index - lastFrameIndexSeen is not 1)
403+
{
404+
contiguous = false;
405+
break;
406+
}
407+
lastFrameIndexSeen = index;
397408
if (index == CurrentTasMovie.FrameCount // last movie frame can't have input, but can be selected
398409
|| !CurrentTasMovie.BoolIsPressed(index, buttonName))
399410
{
400411
allPressed = false;
401412
break;
402413
}
414+
iSelection++;
415+
}
416+
if (!allPressed)
417+
{
418+
// still need to check for discontinuity
419+
while (iSelection < selection.Length)
420+
{
421+
var index = selection[iSelection];
422+
if (index - lastFrameIndexSeen is not 1)
423+
{
424+
contiguous = false;
425+
break;
426+
}
427+
lastFrameIndexSeen = index;
428+
iSelection++;
429+
}
430+
}
431+
else if (!contiguous)
432+
{
433+
// still need to check for `false` values
434+
allPressed = allPressed && selection.Skip(iSelection - 1) // break'd before checking the next one, so less 1 (and can't get here if `iSelection` is 0 so that's safe)
435+
.All(index => index < CurrentTasMovie.FrameCount // last movie frame can't have input, but can be selected
436+
&& CurrentTasMovie.BoolIsPressed(index, buttonName));
437+
}
438+
// else all contiguous and all `true`
439+
440+
CurrentTasMovie.SetBoolStates(frame: selection[0], count: iSelection, buttonName, val: !allPressed);
441+
var blockStart = iSelection;
442+
lastFrameIndexSeen = selection[iSelection] - 1;
443+
while (iSelection < selection.Length)
444+
{
445+
var index = selection[iSelection];
446+
if (index - lastFrameIndexSeen is not 1)
447+
{
448+
// discontinuity; split off another block, and this is now the start of the next block
449+
CurrentTasMovie.SetBoolStates(frame: selection[blockStart], count: iSelection - blockStart, buttonName, val: !allPressed);
450+
blockStart = iSelection;
451+
}
452+
lastFrameIndexSeen = index;
453+
iSelection++;
403454
}
404-
CurrentTasMovie.SetBoolStates(frame: selection[0], count: selection.Length, buttonName, val: !allPressed);
455+
CurrentTasMovie.SetBoolStates(frame: selection[blockStart], count: iSelection - blockStart, buttonName, val: !allPressed);
405456
}
406457
else
407458
{

0 commit comments

Comments
 (0)