diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts index 270d96265..9fcdf9a75 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -5,7 +5,6 @@ import {Constants} from "../constants"; import {fetchPost} from "../util/fetch"; import {disabledProtyle, onGet} from "../protyle/util/onGet"; import {addLoading} from "../protyle/ui/initUI"; -import {focusBlock} from "../protyle/util/selection"; import {scrollCenter} from "../util/highlightById"; import {hasClosestByAttribute} from "../protyle/util/hasClosest"; import {setEditMode} from "../protyle/util/setEditMode"; diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts index 076e8dab9..cf9f66a56 100644 --- a/app/src/mobile/util/keyboardToolbar.ts +++ b/app/src/mobile/util/keyboardToolbar.ts @@ -5,7 +5,7 @@ import {Constants} from "../../constants"; import {focusByRange, getSelectionPosition} from "../../protyle/util/selection"; let renderKeyboardToolbarTimeout: number; -let showKeyboardToolbarUtil = false; +let showUtil = false; const getSlashItem = (value: string, icon: string, text: string, focus = "false") => { let iconHTML; @@ -145,18 +145,23 @@ const renderSlashMenu = (protyle: IProtyle, toolbarElement: Element) => { protyle.hint.bindUploadEvent(protyle, utilElement); }; -const renderKeyboardToolbarUtil = () => { +const showKeyboardToolbarUtil = (oldScrollTop: number) => { const toolbarElement = document.getElementById("keyboardToolbar"); const keyboardHeight = (parseInt(toolbarElement.getAttribute("data-keyboardheight")) + 42) + "px"; toolbarElement.style.height = keyboardHeight; window.siyuan.mobile.editor.protyle.element.style.marginBottom = keyboardHeight; window.siyuan.menus.menu.remove(); - showKeyboardToolbarUtil = true; + showUtil = true; setTimeout(() => { - showKeyboardToolbarUtil = false; + showUtil = false; }, 1000); }; +const hideKeyboardToolbarUtil = () => { + document.getElementById("keyboardToolbar").style.height = ""; + window.siyuan.mobile.editor.protyle.element.style.marginBottom = "42px"; +}; + const renderKeyboardToolbar = () => { clearTimeout(renderKeyboardToolbarTimeout); renderKeyboardToolbarTimeout = window.setTimeout(() => { @@ -230,11 +235,6 @@ const renderKeyboardToolbar = () => { }, 620); // 需等待 range 更新 }; -const hideKeyboardToolbarUtil = () => { - document.getElementById("keyboardToolbar").style.height = ""; - window.siyuan.mobile.editor.protyle.element.style.marginBottom = ""; -}; - export const showKeyboardToolbar = (height: number) => { if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) { return; @@ -251,6 +251,7 @@ export const showKeyboardToolbar = (height: number) => { !window.siyuan.mobile.editor.protyle.wysiwyg.element.contains(range.startContainer)) { return; } + window.siyuan.mobile.editor.protyle.element.style.marginBottom = "42px"; setTimeout(() => { const contentElement = window.siyuan.mobile.editor.protyle.contentElement; const cursorTop = getSelectionPosition(contentElement).top - contentElement.getBoundingClientRect().top; @@ -266,11 +267,13 @@ export const showKeyboardToolbar = (height: number) => { }; export const hideKeyboardToolbar = () => { - if (showKeyboardToolbarUtil) { + if (showUtil) { return; } const toolbarElement = document.getElementById("keyboardToolbar"); toolbarElement.classList.add("fn__none"); + toolbarElement.style.height = ""; + window.siyuan.mobile.editor.protyle.element.style.marginBottom = ""; }; export const activeBlur = () => { @@ -406,8 +409,9 @@ export const initKeyboardToolbar = () => { focusByRange(range); return; } else if (type === "add") { + const oldScrollTop = window.siyuan.mobile.editor.protyle.contentElement.scrollTop; renderSlashMenu(protyle, toolbarElement); - renderKeyboardToolbarUtil(); + showKeyboardToolbarUtil(oldScrollTop); return; } else if (type === "more") { protyle.breadcrumb.showMenu(protyle, { diff --git a/app/src/protyle/header/Background.ts b/app/src/protyle/header/Background.ts index d64b24be8..6f1f6a2ef 100644 --- a/app/src/protyle/header/Background.ts +++ b/app/src/protyle/header/Background.ts @@ -29,7 +29,7 @@ export class Background { this.element = document.createElement("div"); this.element.className = "protyle-background"; this.element.innerHTML = `
- +
@@ -389,7 +389,8 @@ export class Background { } if (img) { - this.element.style.minHeight = "30vh"; + // 移动端键盘弹起和点击加号需保持滚动高度一致 + this.element.style.minHeight = isMobile() ? "200px" : "30vh"; } else if (icon) { this.element.style.minHeight = (this.tagsElement.clientHeight + 56) + "px"; } else if (tags) {