Variant 1: edit changes history, empty text resets index

This commit is contained in:
Terochi
2022-11-21 09:32:44 +01:00
parent 33b2fe46d9
commit 8f942f130b
3 changed files with 24 additions and 60 deletions

View File

@ -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;