💄 帮助展现位置

This commit is contained in:
Vanessa 2023-01-24 19:36:45 +08:00
parent 3b9ae96dbd
commit a043604e54
3 changed files with 6 additions and 13 deletions

View file

@ -4,22 +4,15 @@ export const setPosition = (element: HTMLElement, x: number, y: number, targetHe
element.style.top = y + "px";
element.style.left = x + "px";
const rect = element.getBoundingClientRect();
// windows 下悬浮菜单在 drag 位置时无法点击
let dragBarHeight = 0;
/// #if !BROWSER
if ("windows" === window.siyuan.config.system.os) {
dragBarHeight = document.getElementById("drag").clientHeight;
}
/// #endif
// 上下超出屏幕
if (rect.bottom > window.innerHeight || rect.top < dragBarHeight) {
if (rect.bottom > window.innerHeight || rect.top < Constants.SIZE_TOOLBAR_HEIGHT) {
const top = y - rect.height - targetHeight;
if (top > dragBarHeight && (top + rect.height) < window.innerHeight - dragBarHeight) {
if (top > Constants.SIZE_TOOLBAR_HEIGHT && (top + rect.height) < window.innerHeight) {
// 上部
element.style.top = top + "px";
} else if (top <= dragBarHeight) {
} else if (top <= Constants.SIZE_TOOLBAR_HEIGHT) {
// 位置超越到屏幕上方外时需移动到屏幕顶部。eg光标在第一个块然后滚动到上方看不见的位置按 ctrl+a
element.style.top = dragBarHeight + "px";
element.style.top = Constants.SIZE_TOOLBAR_HEIGHT + "px";
} else {
// 依旧展现在下部,只是位置上移
element.style.top = Math.max(Constants.SIZE_TOOLBAR_HEIGHT, window.innerHeight - rect.height) + "px";