Reversed indexing

This commit is contained in:
Terochi
2022-11-15 18:10:43 +01:00
committed by Terochi
parent 3d4962e181
commit 44c3e71746

View File

@ -13,7 +13,7 @@ namespace osu.Game.Graphics.UserInterface
public IReadOnlyList<string> MessageHistory => messageHistory; public IReadOnlyList<string> MessageHistory => messageHistory;
private int historyIndex = -1; private int historyIndex;
private string originalMessage = string.Empty; private string originalMessage = string.Empty;
@ -22,7 +22,7 @@ namespace osu.Game.Graphics.UserInterface
Current.ValueChanged += text => Current.ValueChanged += text =>
{ {
if (string.IsNullOrEmpty(text.NewValue)) if (string.IsNullOrEmpty(text.NewValue))
historyIndex = -1; historyIndex = messageHistory.Count;
}; };
} }
@ -31,28 +31,28 @@ namespace osu.Game.Graphics.UserInterface
switch (e.Key) switch (e.Key)
{ {
case Key.Up: case Key.Up:
if (historyIndex == -1) if (historyIndex == messageHistory.Count)
originalMessage = Text; originalMessage = Text;
if (historyIndex == messageHistory.Count - 1) if (historyIndex == 0)
return true; return true;
Text = messageHistory[++historyIndex]; Text = messageHistory[--historyIndex];
return true; return true;
case Key.Down: case Key.Down:
if (historyIndex == -1) if (historyIndex == messageHistory.Count)
return true; return true;
if (historyIndex == 0) if (historyIndex == messageHistory.Count - 1)
{ {
historyIndex = -1; historyIndex = messageHistory.Count;
Text = originalMessage; Text = originalMessage;
return true; return true;
} }
Text = messageHistory[--historyIndex]; Text = messageHistory[++historyIndex];
return true; return true;
} }
@ -63,9 +63,9 @@ namespace osu.Game.Graphics.UserInterface
protected override void Commit() protected override void Commit()
{ {
if (!string.IsNullOrEmpty(Text)) if (!string.IsNullOrEmpty(Text))
messageHistory.Insert(0, Text); messageHistory.Add(Text);
historyIndex = -1; historyIndex = messageHistory.Count;
base.Commit(); base.Commit();
} }