@@ -1187,15 +1187,17 @@ function RemoteFunctions(config) {
11871187 window . document . body . appendChild ( highlight ) ;
11881188 } ,
11891189
1190- add : function ( element , doAnimation ) {
1190+ // shouldAutoScroll is whether to scroll page to element if not in view
1191+ // true when user clicks on the source code of some element, in that case we want to scroll the live preview
1192+ add : function ( element , doAnimation , shouldAutoScroll ) {
11911193 if ( this . _elementExists ( element ) || element === window . document ) {
11921194 return ;
11931195 }
11941196 if ( this . trigger ) {
11951197 _trigger ( element , "highlight" , 1 ) ;
11961198 }
11971199
1198- if ( ( ! window . event || window . event instanceof MessageEvent ) && ! isInViewport ( element ) ) {
1200+ if ( shouldAutoScroll && ( ! window . event || window . event instanceof MessageEvent ) && ! isInViewport ( element ) ) {
11991201 var top = getDocumentOffsetTop ( element ) ;
12001202 if ( top ) {
12011203 top -= ( window . innerHeight / 2 ) ;
@@ -1237,7 +1239,7 @@ function RemoteFunctions(config) {
12371239
12381240 this . clear ( ) ;
12391241 for ( i = 0 ; i < highlighted . length ; i ++ ) {
1240- this . add ( highlighted [ i ] , false ) ;
1242+ this . add ( highlighted [ i ] , false , false ) ; // 3rd arg is for auto-scroll
12411243 }
12421244 }
12431245 } ;
@@ -1257,7 +1259,7 @@ function RemoteFunctions(config) {
12571259 // Skip highlighting for HTML, BODY tags and elements inside HEAD
12581260 if ( event . target && event . target . nodeType === Node . ELEMENT_NODE &&
12591261 event . target . tagName !== "HTML" && event . target . tagName !== "BODY" && ! _isInsideHeadTag ( event . target ) ) {
1260- _localHighlight . add ( event . target , true ) ;
1262+ _localHighlight . add ( event . target , true , false ) ; // false means no-auto scroll
12611263 }
12621264 }
12631265 }
@@ -1314,7 +1316,7 @@ function RemoteFunctions(config) {
13141316 event . target . _originalBackgroundColor = event . target . style . backgroundColor ;
13151317 event . target . style . backgroundColor = "rgba(0, 162, 255, 0.2)" ;
13161318
1317- _hoverHighlight . add ( event . target , false ) ;
1319+ _hoverHighlight . add ( event . target , false , false ) ; // false means no auto-scroll
13181320
13191321 // Create info box for the hovered element
13201322 if ( _nodeInfoBox ) {
@@ -1417,7 +1419,7 @@ function RemoteFunctions(config) {
14171419
14181420 if ( _hoverHighlight ) {
14191421 _hoverHighlight . clear ( ) ;
1420- _hoverHighlight . add ( element , true ) ; // true for animation
1422+ _hoverHighlight . add ( element , true , false ) ; // false means no auto-scroll
14211423 }
14221424 }
14231425
@@ -1524,7 +1526,7 @@ function RemoteFunctions(config) {
15241526 // Skip highlighting for HTML, BODY tags and elements inside HEAD
15251527 if ( node && node . nodeType === Node . ELEMENT_NODE &&
15261528 node . tagName !== "HTML" && node . tagName !== "BODY" && ! _isInsideHeadTag ( node ) ) {
1527- _clickHighlight . add ( node , true ) ;
1529+ _clickHighlight . add ( node , true , true ) ; // 3rd arg is for auto-scroll
15281530 }
15291531 }
15301532
0 commit comments