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.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
import net.runelite.client.config.Keybind;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
@ConfigGroup("chatcommands")
|
@ConfigGroup("chatcommands")
|
||||||
public interface ChatCommandsConfig extends Config
|
public interface ChatCommandsConfig extends Config
|
||||||
@@ -121,12 +124,23 @@ public interface ChatCommandsConfig extends Config
|
|||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 8,
|
position = 8,
|
||||||
keyName = "clearShortcuts",
|
keyName = "clearSingleWord",
|
||||||
name = "Clear shortcuts",
|
name = "Clear Single Word",
|
||||||
description = "Enable shortcuts (ctrl+w and backspace) for clearing the chatbox"
|
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
|
@Override
|
||||||
public void keyPressed(KeyEvent e)
|
public void keyPressed(KeyEvent e)
|
||||||
{
|
{
|
||||||
if (!e.isControlDown() || !chatCommandsConfig.clearShortcuts())
|
if (chatCommandsConfig.clearSingleWord().matches(e))
|
||||||
{
|
{
|
||||||
return;
|
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||||
}
|
if (input != null)
|
||||||
|
{
|
||||||
switch (e.getKeyCode())
|
// remove trailing space
|
||||||
{
|
while (input.endsWith(" "))
|
||||||
case KeyEvent.VK_W:
|
|
||||||
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
|
||||||
if (input != null)
|
|
||||||
{
|
{
|
||||||
// remove trailing space
|
input = input.substring(0, input.length() - 1);
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
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(() ->
|
clientThread.invoke(() ->
|
||||||
{
|
{
|
||||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
|
||||||
client.runScript(ScriptID.CHAT_PROMPT_INIT);
|
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