diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2022-05-16 21:45:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-16 21:45:22 -0400 |
commit | 63d37c872b786abe9233d70b2eff0362582cbc3a (patch) | |
tree | e3fd32f96b3734070876e8623acacc76666a0edf /ext/js/app/popup-factory.js | |
parent | 96f5a06c80b985a503a1e30e2cb6d346cb361aba (diff) |
Popup positioning improvements (#2135)
* Rename elementRect to sourceRect
* Add getRects function to TextSourceElement and TextSourceRange
* Add jsdocs
* Remove unnecessary valid parameter
* Remove default parameter
* Make optionsContext optional
* Remove unnecessary checks
* Update sourceRect to use left/right rather than x/y
* Update the return type of Popup*.getFrameRect
* Rename some unrelated rect vars for disambiguation
* Disambiguate between Popup.Rect and Popup.ValidRect
* Move sourceRect destructuring
* Pass multiple source rects
* Simplify
* Change Rect to use right/bottom rather than width/height
* Update how popup offset is applied
* Simplify frame offset
* Remove _applyFrameOffset
* Use right/bottom rather than width/height
* Simplify some positioning settings
* Update parameter names for clarity
* Fix typos
* Refactor data type for _getPosition* functions
* Support using multiple source rects
* Combine _getPosition functions
* Refactor
* Expose after dataset value
* Consistently use this's property
* Add jsdoc
Diffstat (limited to 'ext/js/app/popup-factory.js')
-rw-r--r-- | ext/js/app/popup-factory.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/ext/js/app/popup-factory.js b/ext/js/app/popup-factory.js index fb4a7b8b..bef687ff 100644 --- a/ext/js/app/popup-factory.js +++ b/ext/js/app/popup-factory.js @@ -250,7 +250,9 @@ class PopupFactory { async _onApiContainsPoint({id, x, y}) { const popup = this._getPopup(id); - [x, y] = this._convertPopupPointToRootPagePoint(popup, x, y); + const offset = this._getPopupOffset(popup); + x += offset.x; + y += offset.y; return await popup.containsPoint(x, y); } @@ -258,9 +260,13 @@ class PopupFactory { const popup = this._getPopup(id); if (!this._popupCanShow(popup)) { return; } - const {elementRect} = details; - if (typeof elementRect !== 'undefined') { - [elementRect.x, elementRect.y] = this._convertPopupPointToRootPagePoint(popup, elementRect.x, elementRect.y); + const offset = this._getPopupOffset(popup); + const {sourceRects} = details; + for (const sourceRect of sourceRects) { + sourceRect.left += offset.x; + sourceRect.top += offset.y; + sourceRect.right += offset.x; + sourceRect.bottom += offset.y; } return await popup.showContent(details, displayDetails); @@ -311,16 +317,15 @@ class PopupFactory { return popup; } - _convertPopupPointToRootPagePoint(popup, x, y) { + _getPopupOffset(popup) { const {parent} = popup; if (parent !== null) { const popupRect = parent.getFrameRect(); if (popupRect.valid) { - x += popupRect.x; - y += popupRect.y; + return {x: popupRect.left, y: popupRect.top}; } } - return [x, y]; + return {x: 0, y: 0}; } _popupCanShow(popup) { |