mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:32:55 +08:00
Fix selection not being retained in control point list when undoing / redoing
This commit is contained in:
parent
f2c0e7cf2e
commit
1f2f749db6
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.LocalisationExtensions;
|
using osu.Framework.Extensions.LocalisationExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -46,15 +47,42 @@ namespace osu.Game.Screens.Edit
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetSelectedRow(object? item)
|
protected int GetIndexForObject(object? item)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < BackgroundFlow.Count; i++)
|
||||||
|
{
|
||||||
|
if (BackgroundFlow[i].Item == item)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool SetSelectedRow(object? item)
|
||||||
|
{
|
||||||
|
bool foundSelection = false;
|
||||||
|
|
||||||
foreach (var b in BackgroundFlow)
|
foreach (var b in BackgroundFlow)
|
||||||
{
|
{
|
||||||
b.Selected = ReferenceEquals(b.Item, item);
|
b.Selected = ReferenceEquals(b.Item, item);
|
||||||
|
|
||||||
if (b.Selected)
|
if (b.Selected)
|
||||||
|
{
|
||||||
|
Debug.Assert(!foundSelection);
|
||||||
OnRowSelected?.Invoke(b);
|
OnRowSelected?.Invoke(b);
|
||||||
|
foundSelection = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return foundSelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected object? GetObjectAtIndex(int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index > BackgroundFlow.Count - 1)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return BackgroundFlow[index].Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateHeader(int index, TableColumn? column) => new HeaderText(column?.Header ?? default);
|
protected override Drawable CreateHeader(int index, TableColumn? column) => new HeaderText(column?.Header ?? default);
|
||||||
|
@ -21,7 +21,7 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
public partial class ControlPointTable : EditorTable
|
public partial class ControlPointTable : EditorTable
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<ControlPointGroup> selectedGroup { get; set; } = null!;
|
private Bindable<ControlPointGroup?> selectedGroup { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private EditorClock clock { get; set; } = null!;
|
private EditorClock clock { get; set; } = null!;
|
||||||
@ -32,6 +32,8 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
int selectedIndex = GetIndexForObject(selectedGroup.Value);
|
||||||
|
|
||||||
Content = null;
|
Content = null;
|
||||||
BackgroundFlow.Clear();
|
BackgroundFlow.Clear();
|
||||||
|
|
||||||
@ -53,7 +55,11 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
Columns = createHeaders();
|
Columns = createHeaders();
|
||||||
Content = value.Select(createContent).ToArray().ToRectangular();
|
Content = value.Select(createContent).ToArray().ToRectangular();
|
||||||
|
|
||||||
updateSelectedGroup();
|
if (!SetSelectedRow(selectedGroup.Value))
|
||||||
|
{
|
||||||
|
// Some operations completely obliterate references, so best-effort reselect based on index.
|
||||||
|
selectedGroup.Value = GetObjectAtIndex(selectedIndex) as ControlPointGroup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,11 +67,9 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
selectedGroup.BindValueChanged(_ => updateSelectedGroup(), true);
|
selectedGroup.BindValueChanged(_ => SetSelectedRow(selectedGroup.Value), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelectedGroup() => SetSelectedRow(selectedGroup.Value);
|
|
||||||
|
|
||||||
private TableColumn[] createHeaders()
|
private TableColumn[] createHeaders()
|
||||||
{
|
{
|
||||||
var columns = new List<TableColumn>
|
var columns = new List<TableColumn>
|
||||||
|
Loading…
Reference in New Issue
Block a user