Variant 4: cannot change history, empty text/everything selected resets index (current with bug fix)

This commit is contained in:
Terochi
2022-11-21 10:11:26 +01:00
parent 58288275a6
commit 7dc7729ac2
2 changed files with 36 additions and 1 deletions

View File

@ -22,6 +22,7 @@ namespace osu.Game.Graphics.UserInterface
private int selectedIndex;
private string originalMessage = string.Empty;
private bool everythingSelected;
/// <summary>
/// Creates a new <see cref="HistoryTextBox"/>.
@ -33,6 +34,29 @@ namespace osu.Game.Graphics.UserInterface
public HistoryTextBox(int capacity = 100)
{
messageHistory = new LimitedCapacityQueue<string>(capacity);
Current.ValueChanged += text =>
{
if (string.IsNullOrEmpty(text.NewValue) || everythingSelected)
{
selectedIndex = HistoryCount;
everythingSelected = false;
}
};
}
protected override void OnTextDeselected()
{
base.OnTextDeselected();
everythingSelected = false;
}
protected override void OnTextSelectionChanged(TextSelectionType selectionType)
{
base.OnTextSelectionChanged(selectionType);
everythingSelected = SelectedText == Text;
}
protected override bool OnKeyDown(KeyDownEvent e)
@ -43,6 +67,8 @@ namespace osu.Game.Graphics.UserInterface
if (selectedIndex == 0)
return true;
everythingSelected = false;
if (selectedIndex == HistoryCount)
originalMessage = Text;
@ -54,6 +80,8 @@ namespace osu.Game.Graphics.UserInterface
if (selectedIndex == HistoryCount)
return true;
everythingSelected = false;
if (selectedIndex == HistoryCount - 1)
{
selectedIndex = HistoryCount;