@@ -1201,8 +1201,30 @@ function RemoteFunctions(config) {
12011201 window . document . removeEventListener ( "mousemove" , onMouseMove ) ;
12021202 }
12031203
1204+ // helper function to get the current elements highlight mode
1205+ // this is as per user settings (either click or hover)
1206+ function getHighlightMode ( ) {
1207+ return config . elemHighlights ? config . elemHighlights . toLowerCase ( ) : "hover" ;
1208+ }
1209+
1210+ // helper function to check if highlights should show on hover
1211+ function shouldShowHighlightOnHover ( ) {
1212+ return getHighlightMode ( ) !== "click" ;
1213+ }
1214+
1215+ // helper function to clear element background highlighting
1216+ function clearElementBackground ( element ) {
1217+ if ( element . _originalBackgroundColor !== undefined ) {
1218+ element . style . backgroundColor = element . _originalBackgroundColor ;
1219+ } else {
1220+ element . style . backgroundColor = "" ;
1221+ }
1222+ delete element . _originalBackgroundColor ;
1223+ }
1224+
12041225 function onElementHover ( event ) {
1205- if ( _hoverHighlight && config . isLPEditFeaturesActive ) {
1226+ // this is to check the user's settings, if they want to show the elements highlights on hover or click
1227+ if ( _hoverHighlight && config . isLPEditFeaturesActive && shouldShowHighlightOnHover ( ) ) {
12061228 _hoverHighlight . clear ( ) ;
12071229
12081230 // Skip highlighting for HTML and BODY tags and for DOM elements which doesn't have 'data-brackets-id'
@@ -1233,17 +1255,18 @@ function RemoteFunctions(config) {
12331255 }
12341256
12351257 function onElementHoverOut ( event ) {
1236- if ( _hoverHighlight && config . isLPEditFeaturesActive ) {
1258+ // this is to check the user's settings, if they want to show the elements highlights on hover or click
1259+ if ( _hoverHighlight && config . isLPEditFeaturesActive && shouldShowHighlightOnHover ( ) ) {
12371260 _hoverHighlight . clear ( ) ;
12381261
12391262 // Restore original background color
1240- if ( event && event . target && event . target . nodeType === Node . ELEMENT_NODE && event . target . hasAttribute ( "data-brackets-id" ) ) {
1241- if ( event . target . _originalBackgroundColor !== undefined ) {
1242- event . target . style . backgroundColor = event . target . _originalBackgroundColor ;
1243- } else {
1244- event . target . style . backgroundColor = "" ;
1245- }
1246- delete event . target . _originalBackgroundColor ;
1263+ if (
1264+ event &&
1265+ event . target &&
1266+ event . target . nodeType === Node . ELEMENT_NODE &&
1267+ event . target . hasAttribute ( "data-brackets-id" )
1268+ ) {
1269+ clearElementBackground ( event . target ) ;
12471270 }
12481271
12491272 // Remove info box when mouse leaves the element
@@ -1284,6 +1307,11 @@ function RemoteFunctions(config) {
12841307 previouslyClickedElement . style . outline = "" ;
12851308 }
12861309 delete previouslyClickedElement . _originalOutline ;
1310+
1311+ // Remove highlighting from previously clicked element
1312+ if ( getHighlightMode ( ) === "click" ) {
1313+ clearElementBackground ( previouslyClickedElement ) ;
1314+ }
12871315 }
12881316
12891317 _nodeMoreOptionsBox = new NodeMoreOptionsBox ( event . target ) ;
@@ -1296,6 +1324,18 @@ function RemoteFunctions(config) {
12961324
12971325 event . target . _originalOutline = event . target . style . outline ;
12981326 event . target . style . outline = "1px solid #4285F4" ;
1327+
1328+ // Add highlight for click mode
1329+ if ( getHighlightMode ( ) === "click" ) {
1330+ event . target . _originalBackgroundColor = event . target . style . backgroundColor ;
1331+ event . target . style . backgroundColor = "rgba(0, 162, 255, 0.2)" ;
1332+
1333+ if ( _hoverHighlight ) {
1334+ _hoverHighlight . clear ( ) ;
1335+ _hoverHighlight . add ( event . target , true ) ; // true for animation
1336+ }
1337+ }
1338+
12991339 previouslyClickedElement = event . target ;
13001340 } else if ( // when user clicks on the HTML or the BODY tag, we want to remove the boxes
13011341 _nodeMoreOptionsBox &&
@@ -1724,6 +1764,37 @@ function RemoteFunctions(config) {
17241764 _nodeMoreOptionsBox = null ;
17251765 }
17261766 }
1767+
1768+ // Handle element highlight mode changes for instant switching
1769+ const oldHighlightMode = oldConfig . elemHighlights ? oldConfig . elemHighlights . toLowerCase ( ) : "hover" ;
1770+ const newHighlightMode = getHighlightMode ( ) ;
1771+
1772+ if ( oldHighlightMode !== newHighlightMode ) {
1773+ // Clear any existing highlights when mode changes
1774+ if ( _hoverHighlight ) {
1775+ _hoverHighlight . clear ( ) ;
1776+ }
1777+
1778+ // Clean up any previously highlighted elements
1779+ if ( previouslyClickedElement ) {
1780+ clearElementBackground ( previouslyClickedElement ) ;
1781+ }
1782+
1783+ // Remove info box when switching modes to avoid confusion
1784+ if ( _nodeInfoBox && ! _nodeMoreOptionsBox ) {
1785+ _nodeInfoBox . remove ( ) ;
1786+ _nodeInfoBox = null ;
1787+ }
1788+
1789+ // Re-setup event listeners based on new mode to ensure proper behavior
1790+ if ( config . highlight && config . isLPEditFeaturesActive ) {
1791+ window . document . removeEventListener ( "mouseover" , onElementHover ) ;
1792+ window . document . removeEventListener ( "mouseout" , onElementHoverOut ) ;
1793+ window . document . addEventListener ( "mouseover" , onElementHover ) ;
1794+ window . document . addEventListener ( "mouseout" , onElementHoverOut ) ;
1795+ }
1796+ }
1797+
17271798 return JSON . stringify ( config ) ;
17281799 }
17291800
@@ -1762,6 +1833,16 @@ function RemoteFunctions(config) {
17621833 previouslyClickedElement . style . outline = "" ;
17631834 }
17641835 delete previouslyClickedElement . _originalOutline ;
1836+
1837+ // Clear click-mode highlighting
1838+ if ( getHighlightMode ( ) === "click" ) {
1839+ clearElementBackground ( previouslyClickedElement ) ;
1840+
1841+ if ( _hoverHighlight ) {
1842+ _hoverHighlight . clear ( ) ;
1843+ }
1844+ }
1845+
17651846 previouslyClickedElement = null ;
17661847 dismissed = true ;
17671848 }
0 commit comments