File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -259,19 +259,26 @@ class LiveTranslatorManager {
259
259
if ( badges . length ) {
260
260
let position = { top : 0 , left : 0 } ;
261
261
try {
262
+ let isVisible ;
262
263
if ( node instanceof Text ) {
263
264
const clientRect = getBoundingClientRect ( node ) ;
264
265
position . top = clientRect . top + window . scrollY ;
265
266
position . left = clientRect . left + window . screenX ;
267
+ isVisible = node . parentElement . contains ( document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 ) ) ;
266
268
}
267
269
else {
268
270
const clientRect = node . getClientRects ( ) [ 0 ] ;
269
271
position . top = clientRect . top + clientRect . height - 10 + window . scrollY ;
270
272
position . left = clientRect . left + window . screenX ;
273
+ isVisible = node . contains ( document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 ) ) ;
274
+ }
275
+ if ( ! isVisible ) {
276
+ continue ;
271
277
}
272
278
}
273
279
catch ( error ) {
274
280
// console.warn('Could not get bounding box for', node);
281
+ continue ;
275
282
}
276
283
const container = document . createElement ( 'span' ) ;
277
284
container . classList . add ( 'live-translator-badge-container' ) ;
Original file line number Diff line number Diff line change @@ -305,17 +305,28 @@ class LiveTranslatorManager {
305
305
if ( badges . length ) {
306
306
let position = { top : 0 , left : 0 }
307
307
try {
308
+ let isVisible
308
309
if ( node instanceof Text ) {
309
310
const clientRect = getBoundingClientRect ( node )
310
311
position . top = clientRect . top + window . scrollY
311
312
position . left = clientRect . left + window . screenX
313
+ isVisible = node . parentElement . contains (
314
+ document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 )
315
+ )
312
316
} else {
313
317
const clientRect = node . getClientRects ( ) [ 0 ]
314
318
position . top = clientRect . top + clientRect . height - 10 + window . scrollY
315
319
position . left = clientRect . left + window . screenX
320
+ isVisible = node . contains (
321
+ document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 )
322
+ )
323
+ }
324
+ if ( ! isVisible ) {
325
+ continue
316
326
}
317
327
} catch ( error ) {
318
328
// console.warn('Could not get bounding box for', node);
329
+ continue
319
330
}
320
331
const container = document . createElement ( 'span' )
321
332
container . classList . add ( 'live-translator-badge-container' )
You can’t perform that action at this time.
0 commit comments