From d0ce905d1bc3fff6e9ca8e61e589f5e3d2219fbb Mon Sep 17 00:00:00 2001 From: q3k Date: Wed, 21 May 2025 12:54:38 +0200 Subject: [PATCH] Do not respond to right alt (Alt Gr) keyboard events. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On some keyboard layouts (eg. pl) the right alt key (a.k.a. Alt Gr) is used in combination with letters to type special characters, eg. AltGr-C makes a 'ć' on a pl keyboard layout. At least on Firefox on macOS it seems like events that would otherwise result in a special character still get passed to keydown and friends. This means that if etherpad handles alt-c, it might swallow someone's intent to type in 'ć' and instead open up the chat window. This could arguably be a bug in Firefox or macOS, as the same doesn't happen in Firefox on Linux/X11. But before I bring the discussion to a wider audience I'd like to at least make the issue go away at etherpad level. --- src/static/js/ace2_inner.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/static/js/ace2_inner.ts b/src/static/js/ace2_inner.ts index 709840f80..654042d69 100644 --- a/src/static/js/ace2_inner.ts +++ b/src/static/js/ace2_inner.ts @@ -2526,7 +2526,15 @@ function Ace2Inner(editorInfo, cssManagers) { const handleKeyEvent = (evt) => { if (!isEditable) return; - const {type, charCode, keyCode, which, altKey, shiftKey} = evt; + const {type, charCode, keyCode, which, shiftKey} = evt; + + // If DOM3 support exists, ensure that the left ALT key was pressed. This + // allows keyboard layouts with special meaning for right-alt-char to + // continue working on Firefox / macOS. + let altKey = evt.altKey; + if (evt.originalEvent.location !== undefined) { + altKey = altKey && evt.originalEvent.location === evt.originalEvent.DOM_KEY_LOCATION_LEFT; + } // Don't take action based on modifier keys going up and down. // Modifier keys do not generate "keypress" events.