From 4e98721ba909fb17dcd07d24aff7ebab7b8f59c9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 6 Sep 2019 15:56:46 +0200 Subject: [PATCH] take bounding box for positioning calculation --- .../views/rooms/MessageComposerFormatBar.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/components/views/rooms/MessageComposerFormatBar.js b/src/components/views/rooms/MessageComposerFormatBar.js index af7bb70e70..8090fb2ad5 100644 --- a/src/components/views/rooms/MessageComposerFormatBar.js +++ b/src/components/views/rooms/MessageComposerFormatBar.js @@ -38,23 +38,10 @@ export default class MessageComposerFormatBar extends React.PureComponent { showAt(selectionRect) { this._formatBarRef.classList.add("mx_MessageComposerFormatBar_shown"); - let leftOffset = 0; - let node = this._formatBarRef; - 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`; + const parentRect = this._formatBarRef.parentElement.getBoundingClientRect(); + this._formatBarRef.style.left = `${selectionRect.left - parentRect.left}px`; // 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() {