From a8500150b0bc5e4c0e78cc71a73a15f6db9a35d8 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Sat, 14 Apr 2018 21:43:19 +0700 Subject: [PATCH 1/2] fixed menu popup on alt --- browser/main/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/browser/main/index.js b/browser/main/index.js index ae906538..3fa682cd 100644 --- a/browser/main/index.js +++ b/browser/main/index.js @@ -24,6 +24,46 @@ document.addEventListener('dragover', function (e) { e.stopPropagation() }) +// prevent menu from popup when alt pressed +// but still able to toggle menu when only alt is pressed +let isAltPressing = false +let isAltWithMouse = false +let isAltWithOtherKey = false +let isOtherKey = false + +document.addEventListener('keydown', function (e) { + if (e.key === 'Alt') { + isAltPressing = true + if (isOtherKey) { + isAltWithOtherKey = true + } + } else { + if (isAltPressing) { + isAltWithOtherKey = true + } + isOtherKey = true + } +}) + +document.addEventListener('mousedown', function (e) { + if (isAltPressing) { + isAltWithMouse = true + } +}) + +document.addEventListener('keyup', function (e) { + if (e.key === 'Alt') { + if (isAltWithMouse || isAltWithOtherKey) { + console.log(isAltWithMouse, isAltWithOtherKey) + e.preventDefault() + } + isAltWithMouse = false + isAltWithOtherKey = false + isAltPressing = false + isOtherKey = false + } +}) + document.addEventListener('click', function (e) { const className = e.target.className if (!className && typeof (className) !== 'string') return From 4a6b22f5b76eb8f025e98f347c1a6e5dba0baa4f Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Sun, 15 Apr 2018 09:18:12 +0700 Subject: [PATCH 2/2] removed console.log used for debuging --- browser/main/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/browser/main/index.js b/browser/main/index.js index 3fa682cd..6e8bdcc5 100644 --- a/browser/main/index.js +++ b/browser/main/index.js @@ -54,7 +54,6 @@ document.addEventListener('mousedown', function (e) { document.addEventListener('keyup', function (e) { if (e.key === 'Alt') { if (isAltWithMouse || isAltWithOtherKey) { - console.log(isAltWithMouse, isAltWithOtherKey) e.preventDefault() } isAltWithMouse = false