fix: 修复 popup 位置 #74

This commit is contained in:
yanmao 2022-01-15 10:45:20 +08:00
parent f1cccb7539
commit ed16059884
2 changed files with 20 additions and 6 deletions

View File

@ -81,8 +81,14 @@ export default class Popup {
}
const topRange = subRanges[0];
const bottomRange = subRanges[subRanges.length - 1];
const topRect = topRange.getBoundingClientRect();
const bottomRect = bottomRange.getBoundingClientRect();
const topRect = topRange
.cloneRange()
.collapse(true)
.getBoundingClientRect();
const bottomRect = bottomRange
.cloneRange()
.collapse(false)
.getBoundingClientRect();
let rootRect: DOMRect | undefined = undefined;
this.showContent(() => {
@ -93,7 +99,8 @@ export default class Popup {
}
this.#align =
bottomRange.startNode.equal(selection.focusNode!) &&
!topRange.startNode.equal(selection.focusNode!)
(!topRange.startNode.equal(selection.focusNode!) ||
selection.focusOffset > selection.anchorOffset)
? 'bottom'
: 'top';
const space = 12;

View File

@ -82,8 +82,14 @@ export default class Popup {
}
const topRange = subRanges[0];
const bottomRange = subRanges[subRanges.length - 1];
const topRect = topRange.getBoundingClientRect();
const bottomRect = bottomRange.getBoundingClientRect();
const topRect = topRange
.cloneRange()
.collapse(true)
.getBoundingClientRect();
const bottomRect = bottomRange
.cloneRange()
.collapse(false)
.getBoundingClientRect();
let rootRect: DOMRect | undefined = undefined;
this.showContent(() => {
@ -94,7 +100,8 @@ export default class Popup {
}
this.#align =
bottomRange.startNode.equal(selection.focusNode!) &&
!topRange.startNode.equal(selection.focusNode!)
(!topRange.startNode.equal(selection.focusNode!) ||
selection.focusOffset > selection.anchorOffset)
? 'bottom'
: 'top';
const space = 12;