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:
parent
c30e70cc57
commit
ffadc7d781
@ -5,6 +5,6 @@ namespace osu.Game.Screens.Edit.Commands
|
||||
{
|
||||
public interface IMergeableCommand : IEditorCommand
|
||||
{
|
||||
public IEditorCommand? MergeWith(IEditorCommand previous);
|
||||
public IMergeableCommand? MergeWith(IEditorCommand previous);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user