From d2be7afa8225d45775d3c3f7cff2e7af11c9c508 Mon Sep 17 00:00:00 2001 From: abose Date: Mon, 30 Dec 2024 11:26:31 +0530 Subject: [PATCH 1/2] fix: accdental triple ctrlx3 press event in windows for ui overlay mode --- src/command/KeyBindingManager.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/command/KeyBindingManager.js b/src/command/KeyBindingManager.js index a80c2b23a9..272fe3ea89 100644 --- a/src/command/KeyBindingManager.js +++ b/src/command/KeyBindingManager.js @@ -1174,13 +1174,20 @@ define(function (require, exports, module) { Control: true, Meta: true }; + let isCtrlDepressed = false; // flag set to true if the user keeps the ctrl key pressed without releasing function _detectTripleCtrlKeyPress(event) { + const isCtrlKeyPressStart = !isCtrlDepressed; + if (ctrlKeyCodes[event.code] && ctrlKeyCodes[event.key]) { + isCtrlDepressed = true; + } if(PreferencesManager && !PreferencesManager.get(PREF_TRIPLE_CTRL_KEY_PRESS_ENABLED)){ return false; } const currentTime = new Date().getTime(); // Get the current time - if (ctrlKeyCodes[event.code] && ctrlKeyCodes[event.key] && !event.shiftKey && !event.altKey) { + if (ctrlKeyCodes[event.code] && ctrlKeyCodes[event.key] && !event.shiftKey && !event.altKey + && isCtrlKeyPressStart) { pressCount++; + isCtrlDepressed = true; if(pressCount === PRESS_ACTIVATE_COUNT && (currentTime - lastCtrlKeyPressTime) <= doublePressInterval) { KeyboardOverlayMode.startOverlayMode(); event.stopPropagation(); @@ -1282,6 +1289,15 @@ define(function (require, exports, module) { _handleKeyEvent, true ); + window.document.body.addEventListener( + "keyup", + (event)=>{ + if (ctrlKeyCodes[event.code] && ctrlKeyCodes[event.key]) { + isCtrlDepressed = false; + } + }, + true + ); document.body.addEventListener('mousemove', ()=>{ if(!mouseCursorHidden){ return; From a0e15dd69cd33487b66d72805ad300c81e732eda Mon Sep 17 00:00:00 2001 From: abose Date: Mon, 30 Dec 2024 11:47:16 +0530 Subject: [PATCH 2/2] fix: accdental triple ctrlx3 press overlay mode integ tests --- test/spec/Keyboard-nav-integ-test.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/spec/Keyboard-nav-integ-test.js b/test/spec/Keyboard-nav-integ-test.js index 37195fef22..fa33782b6c 100644 --- a/test/spec/Keyboard-nav-integ-test.js +++ b/test/spec/Keyboard-nav-integ-test.js @@ -19,7 +19,7 @@ * */ -/*global describe, it, expect, beforeAll, afterAll, awaitsFor, awaitsForDone */ +/*global describe, it, expect, beforeAll, afterAll, awaitsFor, awaitsForDone, awaits */ define(function (require, exports, module) { // Recommended to avoid reloading the integration test window Phoenix instance for each test. @@ -66,12 +66,20 @@ define(function (require, exports, module) { function tripleControlEvent() { keyboardType(Keys.KEY.CONTROL); + keyboardType(Keys.KEY.CONTROL, "keyup"); keyboardType(Keys.KEY.CONTROL); + keyboardType(Keys.KEY.CONTROL, "keyup"); keyboardType(Keys.KEY.CONTROL); } - function keyboardType(key) { - const ctrlEvent = new KeyboardEvent("keydown", { + function tripleControlContinuousEvent() { + keyboardType(Keys.KEY.CONTROL); + keyboardType(Keys.KEY.CONTROL); + keyboardType(Keys.KEY.CONTROL); + } + + function keyboardType(key, type) { + const ctrlEvent = new KeyboardEvent(type || "keydown", { key: key, bubbles: true, // Event bubbles up through the DOM cancelable: true, // Event can be canceled, @@ -118,6 +126,17 @@ define(function (require, exports, module) { }, "overlay to be closed"); }); + it("Should not show overlay on triple control continuous press", async function () { + MainViewManager.setLayoutScheme(1, 1); + await openAnyFile(); + await awaitsFor(()=>{ + return !testWindow.$('#ctrl-nav-overlay').is(":visible"); + }, "overlay to be not visible"); + tripleControlContinuousEvent(); + await awaits(20); // give some time so that we are sure that the overlay didn't come up. + expect(testWindow.$('#ctrl-nav-overlay').is(":visible")).toBeFalse(); + }); + async function _verifyMenuNav() { await _openUiNavMode(); keyboardType(Keys.KEY.ARROW_UP);