mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-15 16:41:07 +08:00
🎨 定位
This commit is contained in:
parent
aa55a11d1c
commit
a3ec74f72c
@ -4,7 +4,7 @@ import {fetchPost} from "../../util/fetch";
|
|||||||
import {processRender} from "./processCode";
|
import {processRender} from "./processCode";
|
||||||
import {highlightRender} from "../render/highlightRender";
|
import {highlightRender} from "../render/highlightRender";
|
||||||
import {blockRender} from "../render/blockRender";
|
import {blockRender} from "../render/blockRender";
|
||||||
import {bgFade} from "../../util/highlightById";
|
import {bgFade, scrollCenter} from "../../util/highlightById";
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {pushBack} from "../../util/backForward";
|
import {pushBack} from "../../util/backForward";
|
||||||
/// #endif
|
/// #endif
|
||||||
@ -391,21 +391,31 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
|
|||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
if (scrollAttr && typeof scrollAttr.scrollTop === "number") {
|
||||||
focusElement.scrollIntoView();
|
|
||||||
} else if (scrollAttr && scrollAttr.scrollTop) {
|
|
||||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||||
|
}
|
||||||
|
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
||||||
|
const contentRect = protyle.contentElement.getBoundingClientRect();
|
||||||
|
const focusRect = focusElement.getBoundingClientRect();
|
||||||
|
if (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom) {
|
||||||
|
scrollCenter(protyle, focusElement);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
protyle.observerLoad?.disconnect();
|
protyle.observerLoad?.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加强定位
|
// 加强定位
|
||||||
protyle.observerLoad = new ResizeObserver(() => {
|
protyle.observerLoad = new ResizeObserver(() => {
|
||||||
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
if (scrollAttr && typeof scrollAttr.scrollTop === "number") {
|
||||||
focusElement.scrollIntoView();
|
|
||||||
} else if (scrollAttr && scrollAttr.scrollTop) {
|
|
||||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||||
}
|
}
|
||||||
|
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
||||||
|
const contentRect = protyle.contentElement.getBoundingClientRect();
|
||||||
|
const focusRect = focusElement.getBoundingClientRect();
|
||||||
|
if (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom) {
|
||||||
|
scrollCenter(protyle, focusElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
protyle.observerLoad.observe(protyle.wysiwyg.element);
|
protyle.observerLoad.observe(protyle.wysiwyg.element);
|
||||||
protyle.observer.unobserve(protyle.wysiwyg.element);
|
protyle.observer.unobserve(protyle.wysiwyg.element);
|
||||||
|
Loading…
Reference in New Issue
Block a user