diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts index 4c63574c7..62fe0d9c4 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -37,6 +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} from "./util/mobileAppUtil"; class App { public plugins: import("../plugin").Plugin[] = []; @@ -105,11 +106,7 @@ class App { editElement = hasClosestByAttribute(event.target, "contenteditable", "true") as HTMLElement; } if (editElement) { - if (window.JSAndroid && window.JSAndroid.showKeyboard) { - window.JSAndroid.showKeyboard(); - } else if (window.JSHarmony && window.JSHarmony.showKeyboard) { - window.JSHarmony.showKeyboard(); - } + callMobileAppShowKeyboard(); } }); window.addEventListener("beforeunload", () => { diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts index af9e9b0b1..5dafa1928 100644 --- a/app/src/mobile/util/keyboardToolbar.ts +++ b/app/src/mobile/util/keyboardToolbar.ts @@ -14,6 +14,7 @@ import {hideElements} from "../../protyle/ui/hideElements"; import {softEnter} from "../../protyle/wysiwyg/enter"; import {isInAndroid, isInHarmony} from "../../protyle/util/compatibility"; import {tabCodeBlock} from "../../protyle/wysiwyg/codeBlock"; +import {callMobileAppShowKeyboard} from "./mobileAppUtil"; let renderKeyboardToolbarTimeout: number; let showUtil = false; @@ -609,11 +610,7 @@ export const initKeyboardToolbar = () => { if (type === "done") { if (toolbarElement.clientHeight > 100) { hideKeyboardToolbarUtil(); - if (window.JSAndroid && window.JSAndroid.showKeyboard) { - window.JSAndroid.showKeyboard(); - } else if (window.JSHarmony && window.JSHarmony.showKeyboard) { - window.JSHarmony.showKeyboard(); - } + callMobileAppShowKeyboard(); setTimeout(() => focusByRange(range), 256); } else { activeBlur(); @@ -696,11 +693,7 @@ export const initKeyboardToolbar = () => { } else if (type === "add") { if (buttonElement.classList.contains("protyle-toolbar__item--current")) { hideKeyboardToolbarUtil(); - if (window.JSAndroid && window.JSAndroid.showKeyboard) { - window.JSAndroid.showKeyboard(); - } else if (window.JSHarmony && window.JSHarmony.showKeyboard) { - window.JSHarmony.showKeyboard(); - } + callMobileAppShowKeyboard(); setTimeout(() => focusByRange(range), 256); } else { (document.activeElement as HTMLElement)?.blur(); diff --git a/app/src/mobile/util/mobileAppUtil.ts b/app/src/mobile/util/mobileAppUtil.ts new file mode 100644 index 000000000..4b1e95dc9 --- /dev/null +++ b/app/src/mobile/util/mobileAppUtil.ts @@ -0,0 +1,7 @@ +export const callMobileAppShowKeyboard = () => { + if (window.JSAndroid && window.JSAndroid.showKeyboard) { + window.JSAndroid.showKeyboard(); + } else if (window.JSHarmony && window.JSHarmony.showKeyboard) { + window.JSHarmony.showKeyboard(); + } +}; diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 2caed317e..d84acca9b 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -38,6 +38,7 @@ import {escapeHtml} from "../../../util/escape"; import {editGalleryItem, openGalleryItemMenu} from "./gallery/util"; import {clearSelect} from "../../util/clear"; import {removeCompressURL} from "../../../util/image"; +import {callMobileAppShowKeyboard} from "../../../mobile/util/mobileAppUtil"; let foldTimeout: number; export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => { @@ -327,7 +328,10 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle if (viewsElement) { viewsElement.classList.add("av__views--show"); } - searchElement.focus(); + callMobileAppShowKeyboard(); + setTimeout(() => { + searchElement.focus(); + }, Constants.TIMEOUT_TRANSITION); event.preventDefault(); event.stopPropagation(); return true;