From df3594bd53c71d06f6e103f6782bb26b970beac4 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 19 Feb 2026 00:37:42 +0100 Subject: Autocomplete on space bar and undo on delete (#1179) * Refactor: Implement the space key as an editing action The space key is no longer a CHAR key but now an EDITING key. This allows changing the behavior of the space bar while allowing custom layout users to define a key outputing a space as before. KeyModifier and ComposeKey are updated to treat the space key as before. * Enter the best suggestion when the space bar is pressed * Refactor: Implement backspace as an editing action * Undo suggestion when delete is pressed The delete key (backspace internally) undoes the suggestion if the last action done was entering the suggestion with either the space bar or the candidates view. * Add an option to enable space bar autocomplete This option is off by default. Undoing a completion with backspace works in any case. * Refactor: Track selection emptyness in CurrentlyTypedWord This removes an expensive RPC call. --- srcs/juloo.keyboard2/KeyValue.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyValue.java') diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index 1fb84f4..769bd29 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -81,6 +81,8 @@ public final class KeyValue implements Comparable DELETE_WORD, FORWARD_DELETE_WORD, SELECTION_CANCEL, + SPACE_BAR, + BACKSPACE, } public static enum Placeholder @@ -401,7 +403,12 @@ public final class KeyValue implements Comparable private static KeyValue editingKey(int symbol, Editing action) { - return editingKey(String.valueOf((char)symbol), action, FLAG_KEY_FONT); + return editingKey(symbol, action, 0); + } + + private static KeyValue editingKey(int symbol, Editing action, int flags) + { + return editingKey(String.valueOf((char)symbol), action, flags | FLAG_KEY_FONT); } /** A key that slides the property specified by [s] by the amount specified @@ -658,7 +665,6 @@ public final class KeyValue implements Comparable case "page_down": return keyeventKey(0xE003, KeyEvent.KEYCODE_PAGE_DOWN, 0); case "home": return keyeventKey(0xE00B, KeyEvent.KEYCODE_MOVE_HOME, FLAG_SMALLER_FONT); case "end": return keyeventKey(0xE00C, KeyEvent.KEYCODE_MOVE_END, FLAG_SMALLER_FONT); - case "backspace": return keyeventKey(0xE011, KeyEvent.KEYCODE_DEL, 0); case "delete": return keyeventKey(0xE010, KeyEvent.KEYCODE_FORWARD_DEL, 0); case "insert": return keyeventKey("Ins", KeyEvent.KEYCODE_INSERT, FLAG_SMALLER_FONT); case "f1": return keyeventKey("F1", KeyEvent.KEYCODE_F1, 0); @@ -680,7 +686,7 @@ public final class KeyValue implements Comparable /* Spaces */ case "\\t": return charKey("\\t", '\t', 0); // Send the tab character case "\\n": return charKey("\\n", '\n', 0); // Send the newline character - case "space": return charKey(0xE00D, ' ', FLAG_SMALLER_FONT | FLAG_GREYED); + case "space": return editingKey(0xE00D, Editing.SPACE_BAR, FLAG_SMALLER_FONT | FLAG_GREYED); case "nbsp": return charKey("\u237d", '\u00a0', FLAG_SMALLER_FONT); case "nnbsp": return charKey("\u2423", '\u202F', FLAG_SMALLER_FONT); @@ -729,6 +735,7 @@ public final class KeyValue implements Comparable case "halfspace": return charKey(0xE018, '\u200C', 0); // zero-width non joiner /* Editing keys */ + case "backspace": return editingKey(0xE011, Editing.BACKSPACE, 0); case "copy": return editingKey(0xE030, Editing.COPY); case "paste": return editingKey(0xE032, Editing.PASTE); case "cut": return editingKey(0xE031, Editing.CUT); -- cgit v1.2.3