From d3e876368cdc0404984cc1e49897c5453b5bd7b1 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 25 Feb 2026 15:09:23 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/17099 --- app/src/boot/globalEvent/event.ts | 4 ++++ app/src/mobile/index.ts | 5 ++++- app/src/mobile/util/mobileAppUtil.ts | 12 +++++++++++- app/src/types/index.d.ts | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.ts index 29ed536e9..738e357d1 100644 --- a/app/src/boot/globalEvent/event.ts +++ b/app/src/boot/globalEvent/event.ts @@ -21,6 +21,7 @@ import {openFileById} from "../../editor/util"; import {checkFold} from "../../util/noRelyPCFunction"; import {hideAllElements} from "../../protyle/ui/hideElements"; import {dragOverScroll, stopScrollAnimation} from "./dragover"; +import {setWebViewFocusable} from "../../mobile/util/mobileAppUtil"; export const initWindowEvent = (app: App) => { document.body.addEventListener("mouseleave", () => { @@ -125,6 +126,9 @@ export const initWindowEvent = (app: App) => { window.siyuan.ctrlIsPressed = false; window.siyuan.shiftIsPressed = false; window.siyuan.altIsPressed = false; + /// #if BROWSER + setWebViewFocusable(); + /// #endif }); window.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => { diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts index bbd825644..ea6a5520a 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -37,7 +37,7 @@ import {correctHotkey} from "../boot/globalEvent/commonHotkey"; import {processIOSPurchaseResponse} from "../util/iOSPurchase"; import {updateControlAlt} from "../protyle/util/hotKey"; import {nbsp2space} from "../protyle/util/normalizeText"; -import {callMobileAppShowKeyboard, canInput} from "./util/mobileAppUtil"; +import {callMobileAppShowKeyboard, canInput, setWebViewFocusable} from "./util/mobileAppUtil"; class App { public plugins: import("../plugin").Plugin[] = []; @@ -180,6 +180,9 @@ class App { window.siyuan.shiftIsPressed = false; window.siyuan.altIsPressed = false; }); + window.addEventListener("blur", (event) => { + setWebViewFocusable(); + }); // 移动端删除键 https://github.com/siyuan-note/siyuan/issues/9259 window.addEventListener("keydown", (event) => { mobileKeydown(siyuanApp, event); diff --git a/app/src/mobile/util/mobileAppUtil.ts b/app/src/mobile/util/mobileAppUtil.ts index 192f19ec2..a998c7bbe 100644 --- a/app/src/mobile/util/mobileAppUtil.ts +++ b/app/src/mobile/util/mobileAppUtil.ts @@ -30,4 +30,14 @@ export const canInput = (element: Element) => { return hasClosestByAttribute(element, "contenteditable", "true"); } return false; -}; \ No newline at end of file +}; + +export const setWebViewFocusable = () => { + if (document.activeElement.tagName === "IFRAME") { + if (window.JSAndroid && window.JSAndroid.setWebViewFocusable) { + window.JSAndroid.setWebViewFocusable(true); + } else if (window.JSHarmony && window.JSHarmony.setWebViewFocusable) { + window.JSHarmony.setWebViewFocusable(true); + } + } +}; diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 291d1d552..f682403f9 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -254,6 +254,7 @@ interface Window { print(title: string, html: string): void getScreenWidthPx(): number exit(): void + setWebViewFocusable(enable: boolean): void }; JSHarmony: { showKeyboard(): void @@ -271,6 +272,7 @@ interface Window { print(title: string, html: string): void getScreenWidthPx(): number exit(): void + setWebViewFocusable(enable: boolean): void }; Protyle: import("../protyle/method").default;