RSyntaxTextArea
RSyntaxTextArea copied to clipboard
Here is a FIX for num Pad cursor keys not working in Linux
Here is the fix for num pad cursor keys on Linux. Run the code before making any RSyntaxTextAreas.
static Map<Integer, Integer> keyStrokeMap = litmap(
KeyEvent.VK_UP, KeyEvent.VK_KP_UP,
KeyEvent.VK_DOWN, KeyEvent.VK_KP_DOWN,
KeyEvent.VK_LEFT, KeyEvent.VK_KP_LEFT,
KeyEvent.VK_RIGHT, KeyEvent.VK_KP_RIGHT
);
static void fixKeys() {
RSyntaxTextAreaDefaultInputMap inputMap = new RSyntaxTextAreaDefaultInputMap();
for (KeyStroke key : inputMap.keys()) {
Integer code = keyStrokeMap.get(key.getKeyCode());
if (code != null)
inputMap.put(KeyStroke.getKeyStroke(code, key.getModifiers()),
inputMap.get(key));
}
UIManager.put("RSyntaxTextAreaUI.inputMap", inputMap);
}
static Map litmap(Object... x) {
HashMap map = new HashMap();
for (int i = 0; i < x.length-1; i += 2)
map.put(x[i], x[i+1]);
return map;
}
Nobody interested in working cursor keys? lol
Here's an additional fix if you use AutoComplete (all of this could be done easier when patching the library itself):
static class NumPadFixingInputMap extends InputMap {
public void put(KeyStroke keyStroke, Object actionMapKey) {
super.put(keyStroke, actionMapKey);
Integer code = keyStrokeMap.get(keyStroke.getKeyCode());
if (code != null)
put(KeyStroke.getKeyStroke(code, keyStroke.getModifiers()), actionMapKey);
}
void replaceOn(JComponent c) {
InputMap im = c.getInputMap();
setParent(im.getParent());
for (KeyStroke key : im.keys())
put(key, im.get(key));
c.setInputMap(JComponent.WHEN_FOCUSED, this);
}
}
new NumPadFixingInputMap().replaceOn(yourSyntaxTextArea);
Both fixes together made the cursors work for me.
Not my project, but I bet a pull-request would be very welcome..!