key remapping: fix clearing input when plugin is turned on

This commit is contained in:
Adam
2019-06-07 19:06:46 -04:00
parent 5f972f5bcc
commit b5acb61771
2 changed files with 5 additions and 8 deletions

View File

@@ -191,23 +191,18 @@ class KeyRemappingListener extends MouseAdapter implements KeyListener
switch (e.getKeyCode()) switch (e.getKeyCode())
{ {
case KeyEvent.VK_ENTER: case KeyEvent.VK_ENTER:
case KeyEvent.VK_ESCAPE:
plugin.setTyping(false); plugin.setTyping(false);
clientThread.invoke(plugin::lockChat); clientThread.invoke(plugin::lockChat);
break; break;
case KeyEvent.VK_ESCAPE:
plugin.setTyping(false);
clientThread.invoke(() ->
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
plugin.lockChat();
});
break;
case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_BACK_SPACE:
// Only lock chat on backspace when the typed text is now empty
if (Strings.isNullOrEmpty(client.getVar(VarClientStr.CHATBOX_TYPED_TEXT))) if (Strings.isNullOrEmpty(client.getVar(VarClientStr.CHATBOX_TYPED_TEXT)))
{ {
plugin.setTyping(false); plugin.setTyping(false);
clientThread.invoke(plugin::lockChat); clientThread.invoke(plugin::lockChat);
} }
break;
} }
} }
} }

View File

@@ -183,6 +183,8 @@ public class KeyRemappingPlugin extends Plugin
if (chatboxInput != null) if (chatboxInput != null)
{ {
chatboxInput.setText(getPlayerNameWithIcon() + ": " + PRESS_ENTER_TO_CHAT); 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, "");
} }
} }