take bounding box for positioning calculation
This commit is contained in:
parent
4876f4c469
commit
4e98721ba9
1 changed files with 3 additions and 16 deletions
|
@ -38,23 +38,10 @@ export default class MessageComposerFormatBar extends React.PureComponent {
|
||||||
|
|
||||||
showAt(selectionRect) {
|
showAt(selectionRect) {
|
||||||
this._formatBarRef.classList.add("mx_MessageComposerFormatBar_shown");
|
this._formatBarRef.classList.add("mx_MessageComposerFormatBar_shown");
|
||||||
let leftOffset = 0;
|
const parentRect = this._formatBarRef.parentElement.getBoundingClientRect();
|
||||||
let node = this._formatBarRef;
|
this._formatBarRef.style.left = `${selectionRect.left - parentRect.left}px`;
|
||||||
while (node.offsetParent) {
|
|
||||||
node = node.offsetParent;
|
|
||||||
leftOffset += node.offsetLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
let topOffset = 0;
|
|
||||||
node = this._formatBarRef;
|
|
||||||
while (node.offsetParent) {
|
|
||||||
node = node.offsetParent;
|
|
||||||
topOffset += node.offsetTop;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._formatBarRef.style.left = `${selectionRect.left - leftOffset}px`;
|
|
||||||
// 12 is half the height of the bar (e.g. to center it) and 16 is an offset that felt ok.
|
// 12 is half the height of the bar (e.g. to center it) and 16 is an offset that felt ok.
|
||||||
this._formatBarRef.style.top = `${selectionRect.top - topOffset - 16 - 12}px`;
|
this._formatBarRef.style.top = `${selectionRect.top - parentRect.top - 16 - 12}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
hide() {
|
hide() {
|
||||||
|
|
Loading…
Reference in a new issue