diff --git a/app/src/mobile/util/showKeyboardToolbar.ts b/app/src/mobile/util/showKeyboardToolbar.ts index 4a5273053..76017c38d 100644 --- a/app/src/mobile/util/showKeyboardToolbar.ts +++ b/app/src/mobile/util/showKeyboardToolbar.ts @@ -18,7 +18,7 @@ export const showKeyboardToolbar = (bottom = 0) => { !window.siyuan.mobileEditor.protyle.wysiwyg.element.contains(range.startContainer)) { return; } - scrollCenter(window.siyuan.mobileEditor.protyle); + scrollCenter(window.siyuan.mobileEditor.protyle, undefined, false, (window.outerHeight - 65) / 2 - 30); }; export const hideKeyboardToolbar = () => { diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.ts index e31f588f2..fea528f15 100644 --- a/app/src/util/highlightById.ts +++ b/app/src/util/highlightById.ts @@ -38,10 +38,14 @@ export const highlightById = (protyle: IProtyle, id: string, top = false) => { } }; -export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false) => { +export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false, offset= 0) => { if (!top && getSelection().rangeCount > 0 && hasClosestBlock(getSelection().getRangeAt(0).startContainer)) { const editorElement = protyle.contentElement; const cursorTop = getSelectionPosition(editorElement).top - editorElement.getBoundingClientRect().top; + if (offset) { // 仅移动端弹起键盘用到 + editorElement.scrollTop = editorElement.scrollTop + cursorTop - offset; + return; + } if (cursorTop < 0) { editorElement.scrollTop = editorElement.scrollTop + cursorTop; } else if (cursorTop > editorElement.clientHeight - 34) {