ref: c224416c76e41f284b318adc51f08c3ed11de8e2
parent: 88f86918bfca1935c07eee7f84d98e32ccc2f593
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sun Jun 25 09:54:21 EDT 2023
Reduce the set of keys from which we generate control characters midend_process_key() has some generic code for converting MOD_CTRL along with a printing character into a control character. This is derived from the Emscripten front-end because browsers don't do this themselves. Most other front ends seem to depend on the platform for this mapping. The mapping was applied to all printable ASCII characters, but this meant that Ctrl+-, which is commonly used by browsers to mean "zoom out" got converted into CR and then CURSOR_SELECT. That was confusing to say the least. So now, the CTRL mapping is only applied to characters in the roughly alphabetic range (0x40 to 0x7f), and MOD_CTRL applied to a character in the range 0x20 to 0x3f gets a return of PKR_UNUSED instead. That means that Ctrl+- in browsers now works properly. I don't think this will affect other front-ends because they're generally a lot less generous about passing MOD_CTRL to the mid-end. I've tested the GTK port nonetheless and not found any problems.
--- a/midend.c
+++ b/midend.c
@@ -1213,15 +1213,21 @@
}
/* Canonicalise CTRL+ASCII. */
- if ((button & MOD_CTRL) && (button & ~MOD_MASK) < 0x80)
+ if ((button & MOD_CTRL) &&
+ (button & ~MOD_MASK) >= 0x40 && (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))
+ if (!IS_CURSOR_MOVE(button & ~MOD_MASK)) {
+ /* reject CTRL+anything odd */
+ if ((button & MOD_CTRL) && (button & ~MOD_MASK) >= 0x20)
+ printf(" -> %d\n", PKR_UNUSED);
+ /* otherwise strip them */
button &= ~(MOD_CTRL | MOD_SHFT);
- /* ... and NUM_KEYPAD only on numbers. */
+ }
+ /* interpret_move() expects NUM_KEYPAD only on numbers. */
if ((button & ~MOD_MASK) < '0' || (button & ~MOD_MASK) > '9')
button &= ~MOD_NUM_KEYPAD;
/*