Add test covering expected UX of range selection

This commit is contained in:
Bartłomiej Dach
2021-09-26 17:45:47 +02:00
parent 0de7db5840
commit 81d160c85a
2 changed files with 101 additions and 0 deletions

View File

@ -1,13 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osuTK;
using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
@ -62,5 +65,35 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
EditorBeatmap.Update(h);
});
}
internal override bool MouseDownSelectionRequested(SelectionBlueprint<HitObject> blueprint, MouseButtonEvent e)
{
if (e.ShiftPressed && e.Button == MouseButton.Left && SelectedItems.Any())
{
handleRangeSelection(blueprint);
return true;
}
return base.MouseDownSelectionRequested(blueprint, e);
}
private void handleRangeSelection(SelectionBlueprint<HitObject> blueprint)
{
var clickedObject = blueprint.Item;
double rangeStart = clickedObject.StartTime;
double rangeEnd = clickedObject.GetEndTime();
foreach (var selectedObject in SelectedItems)
{
rangeStart = Math.Min(rangeStart, selectedObject.StartTime);
rangeEnd = Math.Max(rangeEnd, selectedObject.GetEndTime());
}
EditorBeatmap.SelectedHitObjects.Clear();
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects.Where(obj => isInRange(obj, rangeStart, rangeEnd)));
bool isInRange(HitObject hitObject, double start, double end)
=> hitObject.StartTime >= start && hitObject.GetEndTime() <= end;
}
}
}