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