fix: mousehover keys can be set blank

This commit is contained in:
Gabe
2025-09-25 00:21:51 +08:00
parent 2a46939aa5
commit 261f29c185
4 changed files with 29 additions and 15 deletions

View File

@@ -1318,9 +1318,9 @@ export const I18N = {
zh_TW: `劃詞翻譯的開啟和關閉請到「規則設定」裡面設定。`,
},
mousehover_key_help: {
zh: `默认为“ControlLeft”`,
en: `Defaults is "ControlLeft"`,
zh_TW: `預設為“ControlLeft”`,
zh: `当快捷键置空时表示鼠标悬停直接翻译`,
en: `When the shortcut key is empty, it means that the mouse hovers to translate directly`,
zh_TW: `當快捷鍵置空時表示滑鼠懸停直接翻譯`,
},
autoscan_alt: {
zh: `自动扫描`,

View File

@@ -48,7 +48,7 @@ export const shortcutRegister = (targetKeys = [], fn, target = document) => {
const targetKeySet = new Set(targetKeys);
const onKeyDown = (pressedKeys, event) => {
if (targetKeySet.size > 0 && isSameSet(targetKeySet, pressedKeys)) {
if (isSameSet(targetKeySet, pressedKeys)) {
event.preventDefault();
event.stopPropagation();
fn();

View File

@@ -7,7 +7,7 @@ import {
OPT_STYLE_FUZZY,
GLOBLA_RULE,
DEFAULT_SETTING,
DEFAULT_MOUSEHOVER_KEY,
// DEFAULT_MOUSEHOVER_KEY,
OPT_STYLE_NONE,
DEFAULT_API_SETTING,
} from "../config";
@@ -511,7 +511,15 @@ export class Translator {
targetNode = targetNode.parentElement;
}
this.#hoveredNode = foundNode || startNode;
}, 200);
const { mouseHoverKey } = this.#setting.mouseHoverSetting;
if (mouseHoverKey.length === 0 && !this.#isInitialized) {
this.#init();
}
if (mouseHoverKey.length === 0 && foundNode) {
this.#processNode(foundNode);
}
}, 100);
}
// 创建shadowroot的回调
@@ -535,7 +543,11 @@ export class Translator {
let targetNode = this.#hoveredNode;
if (!targetNode || !this.#observedNodes.has(targetNode)) return;
// 切换该节点翻译状态
this.#toggleTargetNode(targetNode);
}
// 切换节点翻译状态
#toggleTargetNode(targetNode) {
if (this.#processedNodes.has(targetNode)) {
this.#cleanupDirectTranslations(targetNode);
} else {
@@ -598,7 +610,7 @@ export class Translator {
this.#rescanQueue.forEach((t) => this.#rescanContainer(t));
this.#rescanQueue.clear();
this.#isQueueProcessing = false;
}, 200);
}, 100);
}
}
@@ -700,8 +712,8 @@ export class Translator {
// 处理一个待翻译的节点
async #processNode(node) {
if (
!Translator.isElementOrFragment(node) ||
this.#processedNodes.has(node)
this.#processedNodes.has(node) ||
!Translator.isElementOrFragment(node)
) {
return;
}
@@ -1202,9 +1214,10 @@ export class Translator {
this.#setting.mouseHoverSetting.useMouseHover = true;
document.addEventListener("mousemove", this.#boundMouseMoveHandler);
let { mouseHoverKey } = this.#setting.mouseHoverSetting;
const { mouseHoverKey } = this.#setting.mouseHoverSetting;
if (mouseHoverKey.length === 0) {
mouseHoverKey = DEFAULT_MOUSEHOVER_KEY;
// mouseHoverKey = DEFAULT_MOUSEHOVER_KEY;
return;
}
this.#removeKeydownHandler = shortcutRegister(
mouseHoverKey,

View File

@@ -19,9 +19,10 @@ export default function ShortcutInput({
const i18n = useI18n();
const commitChanges = () => {
if (editingKeys.length > 0) {
// if (editingKeys.length > 0) {
// onChange(editingKeys);
// }
onChange(editingKeys);
}
setIsEditing(false);
};