keyremapping: fix race with sending messages and clearing chat input

It is not necessary to clear the chat input when locking chat when a message would be sent.
Currently this races with the key handlers where it can sometimes clear the chatbox input
prior to enter being processed, resulting in dropped messages

This was introduced in b5acb61771
This commit is contained in:
Adam
2019-08-06 08:28:41 -04:00
parent 1082b1b863
commit 0e8d377adf
2 changed files with 10 additions and 4 deletions

View File

@@ -182,10 +182,16 @@ class KeyRemappingListener extends MouseAdapter implements KeyListener
switch (e.getKeyCode())
{
case KeyEvent.VK_ESCAPE:
// When existing typing mode, block the escape key
// When exiting typing mode, block the escape key
// so that it doesn't trigger the in-game hotkeys
e.consume();
// FALLTHROUGH
plugin.setTyping(false);
clientThread.invoke(() ->
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
plugin.lockChat();
});
break;
case KeyEvent.VK_ENTER:
plugin.setTyping(false);
clientThread.invoke(plugin::lockChat);

View File

@@ -88,6 +88,8 @@ public class KeyRemappingPlugin extends Plugin
if (client.getGameState() == GameState.LOGGED_IN)
{
lockChat();
// Clear any typed text
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
}
});
}
@@ -178,8 +180,6 @@ public class KeyRemappingPlugin extends Plugin
if (chatboxInput != null)
{
chatboxInput.setText(getPlayerNameWithIcon() + ": " + PRESS_ENTER_TO_CHAT);
// Typed text can be non-empty on plugin start, so clear it now
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
}
}