@@ -442,6 +442,7 @@ function RemoteFunctions(config) {
442442
443443 // the box width and the positions where it should be placed
444444 const boxWidth = 82 ;
445+ const boxHeight = 40 ; // rough estimate for options box
445446 const scrollLeft = window . pageXOffset || document . documentElement . scrollLeft ;
446447 const scrollTop = window . pageYOffset || document . documentElement . scrollTop ;
447448
@@ -456,8 +457,6 @@ function RemoteFunctions(config) {
456457
457458 // default position (right aligned with element)
458459 let leftPos = elemBounds . right - boxWidth + scrollLeft ;
459-
460- // this will be calculated based on whether we have overlap issue or not
461460 let topPos ;
462461
463462 if ( isOverlap ) {
@@ -475,6 +474,25 @@ function RemoteFunctions(config) {
475474 : elemBounds . top - 30 ) + scrollTop ;
476475 }
477476
477+ const windowWidth = window . innerWidth ;
478+ const windowHeight = window . innerHeight ;
479+ // right edge
480+ if ( leftPos + boxWidth > windowWidth ) {
481+ leftPos = Math . max ( 10 , windowWidth - boxWidth - 10 ) ;
482+ }
483+ // left edge
484+ if ( leftPos < 0 ) {
485+ leftPos = 10 ;
486+ }
487+ // bottom edge
488+ if ( topPos + boxHeight > windowHeight ) {
489+ topPos = Math . max ( 10 , windowHeight - boxHeight - 10 ) ;
490+ }
491+ // top edge
492+ if ( topPos < 0 ) {
493+ topPos = 10 ;
494+ }
495+
478496 // the icons that is displayed in the box
479497 const ICONS = {
480498 arrowUp : `
@@ -656,6 +674,7 @@ function RemoteFunctions(config) {
656674 // Calculate estimated width based on character count
657675 // Formula: base padding + (character count * average character width)
658676 const boxWidth = basePadding + ( charCount * avgCharWidth ) ;
677+ const boxHeight = 40 + ( id ? 16 : 0 ) + ( classes . length > 0 ? 16 : 0 ) ; // rough estimate
659678
660679 // we need to check for overlap if this is from a click
661680 if ( this . isFromClick ) {
@@ -692,6 +711,25 @@ function RemoteFunctions(config) {
692711 }
693712 }
694713
714+ const windowWidth = window . innerWidth ;
715+ const windowHeight = window . innerHeight ;
716+ // right edge
717+ if ( leftPos + boxWidth > windowWidth ) {
718+ leftPos = Math . max ( 10 , windowWidth - boxWidth - 10 ) ;
719+ }
720+ // left edge
721+ if ( leftPos < 0 ) {
722+ leftPos = 10 ;
723+ }
724+ // bottom edge
725+ if ( topPos + boxHeight > windowHeight ) {
726+ topPos = Math . max ( 10 , windowHeight - boxHeight - 10 ) ;
727+ }
728+ // top edge
729+ if ( topPos < 0 ) {
730+ topPos = 10 ;
731+ }
732+
695733 const styles = `
696734 .box {
697735 background-color: #4285F4;
0 commit comments