From 5cd2c1400948459e5aff6294962f3f3756b16f68 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 10 Apr 2023 12:00:51 +0800 Subject: [PATCH] :iphone: https://github.com/siyuan-note/siyuan/issues/7940 --- app/src/mobile/index.ts | 6 ++++-- app/src/mobile/util/keyboardToolbar.ts | 25 ++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts index e6fc19265..42f24cdc7 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -15,7 +15,7 @@ import {promiseTransactions} from "../protyle/wysiwyg/transaction"; import {bootSync} from "../dialog/processSystem"; import {initMessage} from "../dialog/message"; import {goBack} from "./util/MobileBackFoward"; -import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar"; +import {hideKeyboardToolbar} from "./util/keyboardToolbar"; import {getLocalStorage} from "../protyle/util/compatibility"; import {openMobileFileById} from "./editor"; import {getSearch} from "../util/functions"; @@ -84,7 +84,9 @@ class App { new App(); window.goBack = goBack; -window.showKeyboardToolbar = showKeyboardToolbar; +window.showKeyboardToolbar = (height) => { + document.getElementById("keyboardToolbar").setAttribute("data-keyboardheight", (height ? height : window.innerHeight / 2 - 42).toString()); +}; window.hideKeyboardToolbar = hideKeyboardToolbar; window.openFileByURL = (openURL) => { if (openURL && /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(openURL)) { diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts index f6271eab2..b0c4ae81c 100644 --- a/app/src/mobile/util/keyboardToolbar.ts +++ b/app/src/mobile/util/keyboardToolbar.ts @@ -150,7 +150,8 @@ const showKeyboardToolbarUtil = (oldScrollTop: number) => { showUtil = true; const toolbarElement = document.getElementById("keyboardToolbar"); - const keyboardHeight = (parseInt(toolbarElement.getAttribute("data-keyboardheight")) + 42) + "px"; + let keyboardHeight = toolbarElement.getAttribute("data-keyboardheight") + keyboardHeight = (keyboardHeight ? (parseInt(keyboardHeight) + 42) : window.innerHeight / 2) + "px"; window.siyuan.mobile.editor.protyle.element.style.marginBottom = keyboardHeight; window.siyuan.mobile.editor.protyle.contentElement.scrollTop = oldScrollTop; setTimeout(() => { @@ -172,17 +173,20 @@ const hideKeyboardToolbarUtil = () => { const renderKeyboardToolbar = () => { clearTimeout(renderKeyboardToolbarTimeout); renderKeyboardToolbarTimeout = window.setTimeout(() => { - if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) { + if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly || + !document.activeElement || ( + document.activeElement && + document.activeElement.tagName !== "INPUT" && + document.activeElement.tagName !== "TEXTAREA" && + !document.activeElement.classList.contains("protyle-wysiwyg") + )) { + hideKeyboardToolbar(); return; } if (!showUtil) { hideKeyboardToolbarUtil(); } - if (window.innerHeight + 200 > ((window.orientation === 90 || window.orientation === -90) ? screen.width : screen.height)) { - hideKeyboardToolbar(); - return; - } - + showKeyboardToolbar(); const dynamicElements = document.querySelectorAll("#keyboardToolbar .keyboard__dynamic"); const range = getSelection().getRangeAt(0); const isProtyle = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true); @@ -247,13 +251,8 @@ const renderKeyboardToolbar = () => { }, 620); // 需等待 range 更新 }; -export const showKeyboardToolbar = (height: number) => { - if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) { - return; - } +const showKeyboardToolbar = () => { const toolbarElement = document.getElementById("keyboardToolbar"); - toolbarElement.setAttribute("data-keyboardheight", height.toString()); - hideKeyboardToolbarUtil(); if (!toolbarElement.classList.contains("fn__none")) { return; }