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.
This commit is contained in:
Ben Harris
2023-06-25 13:54:21 +01:00
parent 88f86918bf
commit c224416c76

View File

@ -1213,15 +1213,21 @@ int midend_process_key(midend *me, int x, int y, int button)
} }
/* Canonicalise CTRL+ASCII. */ /* 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)); button = button & (0x1f | (MOD_MASK & ~MOD_CTRL));
/* Special handling to make CTRL+SHFT+Z into REDO. */ /* Special handling to make CTRL+SHFT+Z into REDO. */
if ((button & (~MOD_MASK | MOD_SHFT)) == (MOD_SHFT | '\x1A')) if ((button & (~MOD_MASK | MOD_SHFT)) == (MOD_SHFT | '\x1A'))
button = UI_REDO; button = UI_REDO;
/* interpret_move() expects CTRL and SHFT only on cursor keys. */ /* 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); 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') if ((button & ~MOD_MASK) < '0' || (button & ~MOD_MASK) > '9')
button &= ~MOD_NUM_KEYPAD; button &= ~MOD_NUM_KEYPAD;
/* /*