Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accdental triple ctrlx3 press event in windows for ui overlay mode #2015

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/command/KeyBindingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 22 additions & 3 deletions test/spec/Keyboard-nav-integ-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Loading