From 56329f0b40e0983bb5c20007be542cfa27b33793 Mon Sep 17 00:00:00 2001 From: Maarten Sijm <9739541+mpsijm@users.noreply.github.com> Date: Wed, 25 Sep 2024 21:03:56 +0200 Subject: [PATCH 1/2] Fix #2701: Do not show shortcut box when modifier key is pressed --- webapp/public/js/domjudge.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webapp/public/js/domjudge.js b/webapp/public/js/domjudge.js index 0e9dde24ef..810883890e 100644 --- a/webapp/public/js/domjudge.js +++ b/webapp/public/js/domjudge.js @@ -834,6 +834,10 @@ function initializeKeyboardShortcuts() { if (keysCookie != 1 && keysCookie != "") { return; } + // Do not trigger shortcuts if user is pressing Ctrl/Alt/Option/Meta key. + if (e.altKey || e.ctrlKey || e.metaKey) { + return; + } // Check if the user is not typing in an input field. if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') { return; From d0a14d8e7c6525fd96bae54c9c4071ad41c24126 Mon Sep 17 00:00:00 2001 From: Maarten Sijm <9739541+mpsijm@users.noreply.github.com> Date: Wed, 25 Sep 2024 21:14:02 +0200 Subject: [PATCH 2/2] Keyboard shortcuts: also remove box before redirect when pressing Enter, not only on cancel --- webapp/public/js/domjudge.js | 50 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/webapp/public/js/domjudge.js b/webapp/public/js/domjudge.js index 810883890e..97dd01eb73 100644 --- a/webapp/public/js/domjudge.js +++ b/webapp/public/js/domjudge.js @@ -905,38 +905,40 @@ function initializeKeyboardShortcuts() { if (e.key >= '0' && e.key <= '9') { sequence += e.key; box.text(type + sequence); - } else if (e.key === 'Enter') { - ignore = false; - switch (type) { - case 's': - type = 'submissions'; - break; - case 't': - type = 'teams'; - break; - case 'p': - type = 'problems'; - break; - case 'c': - type = 'clarifications'; - break; - case 'j': - window.location = domjudge_base_url + '/jury/submissions/by-judging-id/' + sequence; - return; - } - var redirect_to = domjudge_base_url + '/jury/' + type; - if (sequence) { - redirect_to += '/' + sequence; - } - window.location = redirect_to; } else { ignore = false; if (box) { box.remove(); } + // We want to reset the `sequence` variable before redirecting, but then we do need to save the value typed by the user + var typedSequence = sequence; sequence = ''; $body.off('keydown'); $body.on('keydown', oldFunc); + if (e.key === 'Enter') { + switch (type) { + case 's': + type = 'submissions'; + break; + case 't': + type = 'teams'; + break; + case 'p': + type = 'problems'; + break; + case 'c': + type = 'clarifications'; + break; + case 'j': + type = 'submissions/by-judging-id'; + break; + } + var redirect_to = domjudge_base_url + '/jury/' + type; + if (typedSequence) { + redirect_to += '/' + typedSequence; + } + window.location = redirect_to; + } } }); }