mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:42:56 +08:00
Variant 1: edit changes history, empty text resets index
This commit is contained in:
parent
33b2fe46d9
commit
8f942f130b
@ -3,7 +3,6 @@
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -64,62 +63,32 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEmptyHistory()
|
||||
public void TestChangedHistory()
|
||||
{
|
||||
addMessages(2);
|
||||
AddStep("Set text", () => box.Text = temp);
|
||||
AddStep("Move up", () => InputManager.Key(Key.Up));
|
||||
|
||||
AddStep("Change text", () => box.Text = "New message");
|
||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||
AddAssert("Text is the same", () => box.Text == temp);
|
||||
|
||||
AddStep("Move Up", () => InputManager.Key(Key.Up));
|
||||
AddAssert("Text is the same", () => box.Text == temp);
|
||||
AddStep("Move up", () => InputManager.Key(Key.Up));
|
||||
AddAssert("Changes kept", () => box.Text == "New message");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPartialHistory()
|
||||
public void TestInputOnEdge()
|
||||
{
|
||||
addMessages(2);
|
||||
AddStep("Set text", () => box.Text = temp);
|
||||
|
||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||
AddAssert("Text is the same", () => box.Text == temp);
|
||||
AddAssert("Text unchanged", () => box.Text == temp);
|
||||
|
||||
AddRepeatStep("Move Up", () => InputManager.Key(Key.Up), 2);
|
||||
AddRepeatStep("Move up", () => InputManager.Key(Key.Up), 2);
|
||||
AddAssert("Same as 1st message", () => box.Text == "Message 1");
|
||||
|
||||
AddStep("Move Up", () => InputManager.Key(Key.Up));
|
||||
AddAssert("Text is the same", () => box.Text == "Message 1");
|
||||
|
||||
AddRepeatStep("Move down", () => InputManager.Key(Key.Down), 2);
|
||||
AddAssert("Same as temp message", () => box.Text == temp);
|
||||
|
||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||
AddAssert("Text is the same", () => box.Text == temp);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFullHistory()
|
||||
{
|
||||
addMessages(5);
|
||||
AddStep("Set text", () => box.Text = temp);
|
||||
|
||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||
AddAssert("Text is the same", () => box.Text == temp);
|
||||
|
||||
addMessages(2);
|
||||
AddStep("Set text", () => box.Text = temp);
|
||||
|
||||
AddRepeatStep("Move Up", () => InputManager.Key(Key.Up), 5);
|
||||
AddAssert("Same as 3rd message", () => box.Text == "Message 3");
|
||||
|
||||
AddStep("Move Up", () => InputManager.Key(Key.Up));
|
||||
AddAssert("Text is the same", () => box.Text == "Message 3");
|
||||
|
||||
AddRepeatStep("Move down", () => InputManager.Key(Key.Down), 4);
|
||||
AddAssert("Same as previous message", () => box.Text == "Message 7");
|
||||
|
||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||
AddAssert("Same as temp message", () => box.Text == temp);
|
||||
AddStep("Move up", () => InputManager.Key(Key.Up));
|
||||
AddAssert("Text unchanged", () => box.Text == "Message 1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -133,12 +102,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddStep("Remove text", () => box.Text = string.Empty);
|
||||
AddStep("Move Up", () => InputManager.Key(Key.Up));
|
||||
AddAssert("Same as previous message", () => box.Text == "Message 2");
|
||||
|
||||
AddStep("Move Up", () => InputManager.Key(Key.Up));
|
||||
AddStep("Select text", () => InputManager.Keys(PlatformAction.SelectAll));
|
||||
AddStep("Replace text", () => box.Text = "New text");
|
||||
AddStep("Move Up", () => InputManager.Key(Key.Up));
|
||||
AddAssert("Same as previous message", () => box.Text == "Message 2");
|
||||
}
|
||||
|
||||
private void addMessages(int count)
|
||||
|
@ -22,7 +22,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private int selectedIndex;
|
||||
|
||||
private string originalMessage = string.Empty;
|
||||
private bool everythingSelected;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="HistoryTextBox"/>.
|
||||
@ -37,21 +36,11 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
Current.ValueChanged += text =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(text.NewValue) || everythingSelected)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text.NewValue))
|
||||
selectedIndex = HistoryCount;
|
||||
everythingSelected = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnTextSelectionChanged(TextSelectionType selectionType)
|
||||
{
|
||||
everythingSelected = SelectedText == Text;
|
||||
|
||||
base.OnTextSelectionChanged(selectionType);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
switch (e.Key)
|
||||
@ -62,6 +51,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
if (selectedIndex == HistoryCount)
|
||||
originalMessage = Text;
|
||||
else if (!string.IsNullOrEmpty(Text))
|
||||
messageHistory[selectedIndex] = Text;
|
||||
|
||||
Text = messageHistory[--selectedIndex];
|
||||
|
||||
@ -71,6 +62,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
if (selectedIndex == HistoryCount)
|
||||
return true;
|
||||
|
||||
if (!string.IsNullOrEmpty(Text))
|
||||
messageHistory[selectedIndex] = Text;
|
||||
|
||||
if (selectedIndex == HistoryCount - 1)
|
||||
{
|
||||
selectedIndex = HistoryCount;
|
||||
|
@ -103,6 +103,13 @@ namespace osu.Game.Utils
|
||||
|
||||
return array[(start + index) % capacity];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index < 0 || index >= Count)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
array[(start + index) % capacity] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user