Improves tab completion in chat.
Pressing tab after completion now cycles to the next candidate.
This commit is contained in:
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
readonly ColorPreviewManagerWidget colorPreview;
|
||||
|
||||
List<string> playerNames;
|
||||
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();
|
||||
|
||||
// Listen for connection failures
|
||||
void ConnectionStateChanged(OrderManager om)
|
||||
@@ -509,7 +509,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
chatLabel.Text = teamChat ? "Team:" : "Chat:";
|
||||
return true;
|
||||
};
|
||||
chatTextField.OnTabKey = AutoCompleteText;
|
||||
chatTextField.OnTabKey = () =>
|
||||
{
|
||||
chatTextField.Text = tabCompletion.Complete(chatTextField.Text);
|
||||
chatTextField.CursorPosition = chatTextField.Text.Length;
|
||||
return true;
|
||||
};
|
||||
|
||||
chatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
|
||||
chatTemplate = chatPanel.Get("CHAT_TEMPLATE");
|
||||
@@ -770,7 +775,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
while (players.Children.Count > idx)
|
||||
players.RemoveChild(players.Children[idx]);
|
||||
|
||||
playerNames = orderManager.LobbyInfo.Clients.Select(c => c.Name).ToList();
|
||||
tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList();
|
||||
}
|
||||
|
||||
void OnGameStart()
|
||||
@@ -779,35 +784,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
onStart();
|
||||
}
|
||||
|
||||
bool AutoCompleteText()
|
||||
{
|
||||
var chatText = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||
if (chatText == null || string.IsNullOrEmpty(chatText.Text))
|
||||
return false;
|
||||
|
||||
if (chatText.Text.LastOrDefault() == ' ')
|
||||
return false;
|
||||
|
||||
var suggestion = "";
|
||||
var oneWord = !chatText.Text.Contains(' ');
|
||||
var toComplete = oneWord
|
||||
? chatText.Text
|
||||
: chatText.Text.Substring(chatText.Text.LastIndexOf(' ') + 1);
|
||||
|
||||
suggestion = playerNames.FirstOrDefault(x => x.StartsWith(toComplete, StringComparison.InvariantCultureIgnoreCase));
|
||||
if (suggestion == null)
|
||||
return false;
|
||||
|
||||
if (oneWord)
|
||||
suggestion += ": ";
|
||||
else
|
||||
suggestion = chatText.Text.Substring(0, chatText.Text.Length - toComplete.Length) + suggestion;
|
||||
|
||||
chatText.Text = suggestion;
|
||||
chatText.CursorPosition = chatText.Text.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
class DropDownOption
|
||||
{
|
||||
public string Title;
|
||||
|
||||
Reference in New Issue
Block a user