This commit is contained in:
Vanessa 2022-10-07 18:09:52 +08:00
parent a21e51fa19
commit cd4f4b8094
2 changed files with 6 additions and 2 deletions

View file

@ -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 = () => {

View file

@ -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) {