1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 09:42:54 +08:00

fix mergeable commands

This commit is contained in:
OliBomby 2024-10-10 17:52:57 +02:00
parent c30e70cc57
commit ffadc7d781
4 changed files with 8 additions and 17 deletions

View File

@ -5,6 +5,6 @@ namespace osu.Game.Screens.Edit.Commands
{
public interface IMergeableCommand : IEditorCommand
{
public IEditorCommand? MergeWith(IEditorCommand previous);
public IMergeableCommand? MergeWith(IEditorCommand previous);
}
}

View File

@ -24,10 +24,10 @@ namespace osu.Game.Screens.Edit.Commands
public bool IsRedundant => Position == Target.Position;
public IEditorCommand? MergeWith(IEditorCommand previous)
public IMergeableCommand? MergeWith(IEditorCommand previous)
{
if (previous is MoveCommand moveCommand)
return moveCommand.Target != Target ? null : this;
return moveCommand.Target != Target ? null : moveCommand;
return null;
}

View File

@ -25,10 +25,10 @@ namespace osu.Game.Screens.Edit.Commands
public IEditorCommand CreateUndo() => CreateInstance(Target, Value);
public IEditorCommand? MergeWith(IEditorCommand previous)
public IMergeableCommand? MergeWith(IEditorCommand previous)
{
if (previous is PropertyChangeCommand<TTarget, TProperty> command && command.Target == Target)
return this;
return command;
return null;
}

View File

@ -153,24 +153,15 @@ namespace osu.Game.Screens.Edit
{
if (command is IMergeableCommand mergeable)
{
for (int i = 0; i < commands.Count; i++)
for (int i = commands.Count - 1; i >= 0; i--)
{
var merged = mergeable.MergeWith(commands[i]);
if (merged == null)
continue;
command = merged;
commands.RemoveAt(i--);
if (command is IMergeableCommand newMergeable)
{
mergeable = newMergeable;
}
else
{
break;
}
commands[i] = merged;
return;
}
}