Merge pull request #15989 from bdach/fix-editor-clipboard-test-failure

Fix editor crashing if paste is performed while composer is loading
This commit is contained in:
Dean Herbert
2021-12-08 11:18:59 +09:00
committed by GitHub
2 changed files with 6 additions and 2 deletions

View File

@ -10,6 +10,7 @@ using osu.Game.Beatmaps;
using osu.Game.Overlays.Dialog; using osu.Game.Overlays.Dialog;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Tests.Beatmaps.IO; using osu.Game.Tests.Beatmaps.IO;
@ -89,6 +90,7 @@ namespace osu.Game.Tests.Visual.Editing
confirmEditingBeatmap(() => targetDifficulty); confirmEditingBeatmap(() => targetDifficulty);
AddAssert("no objects selected", () => !EditorBeatmap.SelectedHitObjects.Any()); AddAssert("no objects selected", () => !EditorBeatmap.SelectedHitObjects.Any());
AddUntilStep("wait for drawable ruleset", () => Editor.ChildrenOfType<DrawableRuleset>().SingleOrDefault()?.IsLoaded == true);
AddStep("paste object", () => Editor.Paste()); AddStep("paste object", () => Editor.Paste());
if (sameRuleset) if (sameRuleset)

View File

@ -83,7 +83,9 @@ namespace osu.Game.Screens.Edit.Compose
{ {
base.LoadComplete(); base.LoadComplete();
EditorBeatmap.SelectedHitObjects.BindCollectionChanged((_, __) => updateClipboardActionAvailability()); EditorBeatmap.SelectedHitObjects.BindCollectionChanged((_, __) => updateClipboardActionAvailability());
clipboard.BindValueChanged(_ => updateClipboardActionAvailability(), true); clipboard.BindValueChanged(_ => updateClipboardActionAvailability());
composer.OnLoadComplete += _ => updateClipboardActionAvailability();
updateClipboardActionAvailability();
} }
#region Clipboard operations #region Clipboard operations
@ -131,7 +133,7 @@ namespace osu.Game.Screens.Edit.Compose
private void updateClipboardActionAvailability() private void updateClipboardActionAvailability()
{ {
CanCut.Value = CanCopy.Value = EditorBeatmap.SelectedHitObjects.Any(); CanCut.Value = CanCopy.Value = EditorBeatmap.SelectedHitObjects.Any();
CanPaste.Value = !string.IsNullOrEmpty(clipboard.Value); CanPaste.Value = composer.IsLoaded && !string.IsNullOrEmpty(clipboard.Value);
} }
private string formatSelectionAsString() private string formatSelectionAsString()