From cd4f4b8094e867bfb289fe1c471d6cad11ca891b Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 7 Oct 2022 18:09:52 +0800 Subject: [PATCH] :iphone: fix https://github.com/siyuan-note/siyuan/issues/6074 --- app/src/mobile/util/showKeyboardToolbar.ts | 2 +- app/src/util/highlightById.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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) {