This commit is contained in:
Vanessa 2022-11-07 23:35:22 +08:00
parent c8834231af
commit 0e07612940
2 changed files with 21 additions and 18 deletions

View file

@ -38,18 +38,10 @@ export const highlightById = (protyle: IProtyle, id: string, top = false) => {
}
};
export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false, offset = 0) => {
export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false) => {
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.scroll({
top: editorElement.scrollTop + cursorTop - offset,
left: editorElement.scrollLeft,
behavior: "smooth"
});
return;
}
if (cursorTop < 0) {
editorElement.scrollTop = editorElement.scrollTop + cursorTop;
} else if (cursorTop > editorElement.clientHeight - 34) {