chatcommands: Make chat clearing keybinds configurable (#10308)
Closes #6929
This commit is contained in:
@@ -27,6 +27,9 @@ package net.runelite.client.plugins.chatcommands;
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.config.Keybind;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
@ConfigGroup("chatcommands")
|
||||
public interface ChatCommandsConfig extends Config
|
||||
@@ -121,12 +124,23 @@ public interface ChatCommandsConfig extends Config
|
||||
|
||||
@ConfigItem(
|
||||
position = 8,
|
||||
keyName = "clearShortcuts",
|
||||
name = "Clear shortcuts",
|
||||
description = "Enable shortcuts (ctrl+w and backspace) for clearing the chatbox"
|
||||
keyName = "clearSingleWord",
|
||||
name = "Clear Single Word",
|
||||
description = "Enable hot key to clear single word at a time"
|
||||
)
|
||||
default boolean clearShortcuts()
|
||||
default Keybind clearSingleWord()
|
||||
{
|
||||
return true;
|
||||
return new Keybind(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK);
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 9,
|
||||
keyName = "clearEntireChatBox",
|
||||
name = "Clear Chat Box",
|
||||
description = "Enable hotkey to clear entire chat box"
|
||||
)
|
||||
default Keybind clearChatBox()
|
||||
{
|
||||
return new Keybind(KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,49 +54,43 @@ public class ChatKeyboardListener implements KeyListener
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
if (!e.isControlDown() || !chatCommandsConfig.clearShortcuts())
|
||||
if (chatCommandsConfig.clearSingleWord().matches(e))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_W:
|
||||
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||
if (input != null)
|
||||
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||
if (input != null)
|
||||
{
|
||||
// remove trailing space
|
||||
while (input.endsWith(" "))
|
||||
{
|
||||
// remove trailing space
|
||||
while (input.endsWith(" "))
|
||||
{
|
||||
input = input.substring(0, input.length() - 1);
|
||||
}
|
||||
|
||||
// find next word
|
||||
int idx = input.lastIndexOf(' ');
|
||||
final String replacement;
|
||||
if (idx != -1)
|
||||
{
|
||||
replacement = input.substring(0, idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
replacement = "";
|
||||
}
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
|
||||
client.runScript(ScriptID.CHAT_PROMPT_INIT);
|
||||
});
|
||||
input = input.substring(0, input.length() - 1);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_BACK_SPACE:
|
||||
|
||||
// find next word
|
||||
int idx = input.lastIndexOf(' ');
|
||||
final String replacement;
|
||||
if (idx != -1)
|
||||
{
|
||||
replacement = input.substring(0, idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
replacement = "";
|
||||
}
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
|
||||
client.runScript(ScriptID.CHAT_PROMPT_INIT);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (chatCommandsConfig.clearChatBox().matches(e))
|
||||
{
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||
client.runScript(ScriptID.CHAT_PROMPT_INIT);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user