diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index 41c229634..344746656 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -323,7 +323,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => { return true; } const target = event.target as HTMLElement; - if (target.tagName !== "TABLE" && (target.tagName === "INPUT" || target.tagName === "TEXTAREA")) { + if (target.tagName !== "TABLE" && ["INPUT", "TEXTAREA"].includes(target.tagName)) { return false; } if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) { @@ -653,7 +653,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => { return true; } const target = event.target as HTMLElement; - if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || + if (["INPUT", "TEXTAREA"].includes(target.tagName) || hasClosestByAttribute(target, "contenteditable", null) || hasClosestByClassName(target, "protyle", true)) { return false; @@ -834,7 +834,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => { const panelTreeKeydown = (app: App, event: KeyboardEvent) => { // 面板折叠展开操作 const target = event.target as HTMLElement; - if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || + if (["INPUT", "TEXTAREA"].includes(target.tagName) || hasClosestByAttribute(target, "contenteditable", null) || hasClosestByClassName(target, "protyle", true)) { return false; @@ -1280,7 +1280,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => { event.preventDefault(); return; } - if (matchHotKey("⌘A", event) && target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") { + if (matchHotKey("⌘A", event) && !["INPUT", "TEXTAREA"].includes(target.tagName)) { event.preventDefault(); return; } diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index f002d7ca8..09480ccff 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -213,13 +213,7 @@ export const initWindow = async (app: App) => { ipcRenderer.on(Constants.SIYUAN_EVENT, (event, cmd) => { if (cmd === "focus") { if (getSelection().rangeCount > 0) { - const range = getSelection().getRangeAt(0); - const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement; - if (startNode && startNode.nodeType !== 3 && (startNode.tagName === "TEXTAREA" || startNode.tagName === "INPUT")) { - startNode.focus(); - } else { - focusByRange(getSelection().getRangeAt(0)); - } + focusByRange(getSelection().getRangeAt(0)); } exportLayout({ reload: false, diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts index 677f4a1d0..ef0cf8f9c 100644 --- a/app/src/menus/Menu.ts +++ b/app/src/menus/Menu.ts @@ -253,7 +253,7 @@ export const bindMenuKeydown = (event: KeyboardEvent) => { return false; } const target = event.target as HTMLElement; - if (window.siyuan.menus.menu.element.contains(target) && (target.tagName === "INPUT" || target.tagName === "TEXTAREA")) { + if (window.siyuan.menus.menu.element.contains(target) && ["INPUT", "TEXTAREA"].includes(target.tagName)) { return false; } const eventCode = Constants.KEYCODELIST[event.keyCode]; diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts index 7804e5792..a3c2ba598 100644 --- a/app/src/mobile/util/keyboardToolbar.ts +++ b/app/src/mobile/util/keyboardToolbar.ts @@ -308,8 +308,7 @@ const renderKeyboardToolbar = () => { window.screen.height - window.innerHeight < 160 || // reloadSync 会导致 selectionchange,从而导致键盘没有弹起的情况下出现工具栏 !document.activeElement || ( document.activeElement && - document.activeElement.tagName !== "INPUT" && - document.activeElement.tagName !== "TEXTAREA" && + !["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) && !document.activeElement.classList.contains("protyle-wysiwyg") && document.activeElement.getAttribute("contenteditable") !== "true" )) { @@ -318,8 +317,7 @@ const renderKeyboardToolbar = () => { } // 编辑器设置界面点击空白或关闭,焦点不知何故会飘移到编辑器上 if (document.activeElement && - document.activeElement.tagName !== "INPUT" && - document.activeElement.tagName !== "TEXTAREA" && ( + !["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) && ( document.getElementById("menu").style.transform === "translateX(0px)" || document.getElementById("model").style.transform === "translateY(0px)" )) { diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index 350f8ed5f..8e7887ab2 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -204,16 +204,13 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type }); }); } - inputElement.addEventListener("blur", () => { - updateCellValue(protyle, type, cellElements); - }); inputElement.addEventListener("keydown", (event) => { if (event.isComposing) { return; } if (event.key === "Escape" || event.key === "Tab" || (event.key === "Enter" && !event.shiftKey && isNotCtrl(event))) { - inputElement.blur(); + updateCellValue(protyle, type, cellElements); if (event.key === "Tab") { protyle.wysiwyg.element.dispatchEvent(new KeyboardEvent("keydown", { shiftKey: event.shiftKey, @@ -231,6 +228,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type } avMaskElement.addEventListener("click", (event) => { if ((event.target as HTMLElement).classList.contains("av__mask")) { + updateCellValue(protyle, type, cellElements); avMaskElement?.remove(); } }); diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index e94162a89..2cbc4f4d3 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -296,7 +296,10 @@ ${cell.color ? `color:${cell.color};` : ""}">${text}`; if (newCellElement) { newCellElement.classList.add("av__cell--select"); } - if (!document.querySelector(".av__panel")) { + const avMaskElement = document.querySelector(".av__mask"); + if (avMaskElement) { + (avMaskElement.querySelector(" textarea") as HTMLTextAreaElement).focus(); + } else if (!document.querySelector(".av__panel")) { focusBlock(e); } } diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts index 4b1d09b7d..a4bd198c0 100644 --- a/app/src/protyle/util/selection.ts +++ b/app/src/protyle/util/selection.ts @@ -475,6 +475,12 @@ export const focusByRange = (range: Range) => { if (!range) { return; } + + const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement; + if (startNode && startNode.nodeType !== 3 && ["INPUT", "TEXTAREA"].includes(startNode.tagName)) { + startNode.focus(); + return; + } const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range);