mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-05 16:28:49 +01:00
This commit is contained in:
parent
63aef7a8c0
commit
070fef00fa
1 changed files with 6 additions and 2 deletions
|
|
@ -38,12 +38,16 @@ 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, 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;
|
||||
editorElement.scroll({
|
||||
top: editorElement.scrollLeft,
|
||||
left: editorElement.scrollTop + cursorTop - offset,
|
||||
behavior: "smooth"
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (cursorTop < 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue