File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
src/app/ContentScript/SelectTranslator Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,15 @@ export const getSelectedTextOfInput = (elm: HTMLInputElement | HTMLTextAreaEleme
76
76
return elm . value . slice ( selectionStart , selectionEnd ) ;
77
77
} ;
78
78
79
+ export const getAbsolutePositionOfElement = ( element : HTMLElement ) => {
80
+ const bounds = element . getBoundingClientRect ( ) ;
81
+ const { scrollX = 0 , scrollY = 0 } = window ;
82
+ return {
83
+ x : bounds . x + scrollX ,
84
+ y : bounds . y + scrollY ,
85
+ } ;
86
+ } ;
87
+
79
88
/**
80
89
* This wrapper on component need to allow convenient manage state
81
90
*/
@@ -343,10 +352,10 @@ export class SelectTranslator {
343
352
// the element will be rendered too far of requested coordinates,
344
353
// because element renders related root node
345
354
// See issue #529
346
- const bounds = rootNode . getBoundingClientRect ( ) ;
355
+ const rootPosition = getAbsolutePositionOfElement ( rootNode ) ;
347
356
const fixedPosition = {
348
- x : x - bounds . x ,
349
- y : y - bounds . y ,
357
+ x : x - rootPosition . x ,
358
+ y : y - rootPosition . y ,
350
359
} ;
351
360
352
361
this . shadowRoot . mountComponent (
You can’t perform that action at this time.
0 commit comments