Skip to content

Commit

Permalink
fix edge select menu conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Apr 8, 2024
1 parent a6c5e2c commit 50a9330
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions doc/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ English, Russian, Japanese, Chinese and so on
- 0.1.134
- English AU locale (contributed by CreeperYeeter2)
- fix RTL UI
- fix edge select conflict
- 0.1.133
- fix youtube subtitle conflict
- 0.1.132
Expand Down
30 changes: 13 additions & 17 deletions src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ function loadEventListener() {
addEventHandler("keyup", handleKeyup);
addEventHandler("mousedown", handleMouseKeyDown);
addEventHandler("mouseup", handleMouseKeyUp);
addEventHandler("mouseup", disableEdgeMiniMenu, false);

//detect tab switching to reset env
addEventHandler("blur", resetTooltipStatus);
Expand Down Expand Up @@ -499,31 +500,26 @@ function handleMouseKeyUp(e) {
}

function holdKeydownList(key) {
if (key && !keyDownList[key] && !isCharKey(key)) {
if (key && !keyDownList[key] && !util.isCharKey(key)) {
keyDownList[key] = true;
restartWordProcess();
translateWriting();
}
stopTTSbyCombKey(key);
}

async function stopTTSbyCombKey(key) {
if (!isCharKey(key) || !keyDownList[setting["TTSWhen"]]) {
return;
function disableEdgeMiniMenu(e) {
//prevent mouse tooltip overlap with edge mini menu
if (util.isEdge() && mouseKeyMap[e.button] == "ClickLeft") {
e.preventDefault();
}
// stop tts if combination key ex crtl+c
util.requestStopTTS(Date.now() + 500);
}

function isCharKey(key) {
return /Key|Digit|Numpad/.test(key);
}
function isStageKey(key) {
return [
setting["TTSWhen"],
setting["showTooltipWhen"],
setting["keyDownMouseoverTextSwap"],
].includes(key);
async function stopTTSbyCombKey(key) {
// stop tts if char key like crtl +c
if (util.isCharKey(key)) {
util.requestStopTTS(Date.now() + 500);
}
}

function releaseKeydownList(key) {
Expand Down Expand Up @@ -859,10 +855,10 @@ function destructor() {
controller.abort(); //clear all event Listener by controller signal
}

function addEventHandler(eventName, callbackFunc) {
function addEventHandler(eventName, callbackFunc, capture = true) {
//record event for later event signal kill
return window.addEventListener(eventName, callbackFunc, {
capture: true,
capture: capture,
signal,
});
}
Expand Down
8 changes: 8 additions & 0 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,14 @@ export function isLocalFileUrl(url) {
return /^file:\/\//.test(url);
}

export function isCharKey(key) {
return /Key|Digit|Numpad/.test(key);
}

export function isEdge() {
return /Edg\//.test(window.navigator.userAgent);
}

//send to background.js for background processing ===========================================================================

export async function requestTranslate(
Expand Down

0 comments on commit 50a9330

Please sign in to comment.