aboutsummaryrefslogtreecommitdiff
path: root/midend.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-02-23 22:32:53 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-02-23 23:16:18 +0000
commit9dbcfa765ba59a8201425df18bec09c7bc334c5e (patch)
tree3aeaf692447bb8bbcbfa3cef2afda06cc3d958f7 /midend.c
parent015bd1447472f82a5607ecb5fabaf25bf37cd4e2 (diff)
downloadpuzzles-9dbcfa765ba59a8201425df18bec09c7bc334c5e.zip
puzzles-9dbcfa765ba59a8201425df18bec09c7bc334c5e.tar.gz
puzzles-9dbcfa765ba59a8201425df18bec09c7bc334c5e.tar.bz2
puzzles-9dbcfa765ba59a8201425df18bec09c7bc334c5e.tar.xz
More cleverness in midend_process_key()
It now strips off modifier flags from keys that shouldn't have them and maps printable characters with MOD_CTRL to the corresponding control characters. It also catches Ctrl+Shift+Z because that obviously belongs in the midend. I've updated the JavaScript front-end to take advantage of these changes. Other front ends are unchanged and should work just as they did before.
Diffstat (limited to 'midend.c')
-rw-r--r--midend.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/midend.c b/midend.c
index f566251..2365258 100644
--- a/midend.c
+++ b/midend.c
@@ -1140,6 +1140,10 @@ bool midend_process_key(midend *me, int x, int y, int button, bool *handled)
* of '\n' etc for keyboard-based cursors. The choice of buttons
* here could eventually be controlled by a runtime configuration
* option.
+ *
+ * We also handle converting MOD_CTRL|'a' etc into '\x01' etc,
+ * specially recognising Ctrl+Shift+Z, and stripping modifier
+ * flags off keys that aren't meant to have them.
*/
if (IS_MOUSE_DRAG(button) || IS_MOUSE_RELEASE(button)) {
if (me->pressed_mouse_button) {
@@ -1169,6 +1173,18 @@ bool midend_process_key(midend *me, int x, int y, int button, bool *handled)
(LEFT_RELEASE - LEFT_BUTTON)), handled);
}
+ /* Canonicalise CTRL+ASCII. */
+ if ((button & MOD_CTRL) && (button & ~MOD_MASK) < 0x80)
+ button = button & (0x1f | (MOD_MASK & ~MOD_CTRL));
+ /* Special handling to make CTRL+SHFT+Z into REDO. */
+ if ((button & (~MOD_MASK | MOD_SHFT)) == (MOD_SHFT | '\x1A'))
+ button = UI_REDO;
+ /* interpret_move() expects CTRL and SHFT only on cursor keys. */
+ if (!IS_CURSOR_MOVE(button & ~MOD_MASK))
+ button &= ~(MOD_CTRL | MOD_SHFT);
+ /* ... and NUM_KEYPAD only on ASCII values. */
+ if ((button & ~MOD_MASK) >= 0x80)
+ button &= ~MOD_NUM_KEYPAD;
/*
* Translate keyboard presses to cursor selection.
*/