update: 工具栏 popup 位置问题

This commit is contained in:
yanmao 2022-01-20 15:22:29 +08:00
parent 4259d75920
commit 59f6c77eef
2 changed files with 26 additions and 2 deletions

View File

@ -119,10 +119,22 @@ export default class Popup {
this.#align = 'top';
}
targetRect = this.#align === 'bottom' ? bottomRect : topRect;
const top =
let top =
this.#align === 'top'
? targetRect.top - rootRect.height - space
: targetRect.bottom + space;
if (this.#editor.scrollNode) {
const scrollNodeRect = this.#editor.scrollNode
.get<HTMLElement>()
?.getBoundingClientRect();
if (scrollNodeRect) {
if (top < scrollNodeRect.top) {
top = scrollNodeRect.top;
} else if (top > scrollNodeRect.bottom) {
top = scrollNodeRect.bottom - rootRect.height - space;
}
}
}
this.#point = {
left: targetRect.left + targetRect.width - rootRect.width / 2,
top,

View File

@ -120,10 +120,22 @@ export default class Popup {
this.#align = 'top';
}
targetRect = this.#align === 'bottom' ? bottomRect : topRect;
const top =
let top =
this.#align === 'top'
? targetRect.top - rootRect.height - space
: targetRect.bottom + space;
if (this.#editor.scrollNode) {
const scrollNodeRect = this.#editor.scrollNode
.get<HTMLElement>()
?.getBoundingClientRect();
if (scrollNodeRect) {
if (top < scrollNodeRect.top) {
top = scrollNodeRect.top;
} else if (top > scrollNodeRect.bottom) {
top = scrollNodeRect.bottom - rootRect.height - space;
}
}
}
this.#point = {
left: targetRect.left + targetRect.width - rootRect.width / 2,
top,