@@ -26,10 +26,8 @@ function RemoteFunctions(config = {}) {
2626 __description : "Use this to keep shared state for Live Preview Edit instead of window.*"
2727 } ;
2828
29- let _localHighlight ;
3029 let _hoverHighlight ;
3130 let _clickHighlight ;
32- let _setup = false ;
3331 let _hoverLockTimer = null ;
3432
3533 // this will store the element that was clicked previously (before the new click)
@@ -185,16 +183,6 @@ function RemoteFunctions(config = {}) {
185183 // the below code comment is replaced by added scripts for extensibility
186184 // DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS
187185
188- // determine whether an event should be processed for Live Development
189- function _validEvent ( event ) {
190- if ( window . navigator . platform . substr ( 0 , 3 ) === "Mac" ) {
191- // Mac
192- return event . metaKey ;
193- }
194- // Windows
195- return event . ctrlKey ;
196- }
197-
198186 // helper function to check if an element is inside the HEAD tag
199187 // we need this because we don't wanna trigger the element highlights on head tag and its children,
200188 // except for <style> tags which should be allowed
@@ -575,26 +563,6 @@ function RemoteFunctions(config = {}) {
575563 }
576564 } ;
577565
578- function onMouseOver ( event ) {
579- if ( _validEvent ( event ) ) {
580- const element = event . target ;
581- if ( LivePreviewView . isElementInspectable ( element ) && element . nodeType === Node . ELEMENT_NODE ) {
582- _localHighlight . add ( element , true ) ;
583- }
584- }
585- }
586-
587- function onMouseOut ( event ) {
588- if ( _validEvent ( event ) ) {
589- _localHighlight . clear ( ) ;
590- }
591- }
592-
593- function onMouseMove ( event ) {
594- onMouseOver ( event ) ;
595- window . document . removeEventListener ( "mousemove" , onMouseMove ) ;
596- }
597-
598566 // helper function to get the current elements highlight mode
599567 // this is as per user settings (either click or hover)
600568 function getHighlightMode ( ) {
@@ -727,14 +695,6 @@ function RemoteFunctions(config = {}) {
727695 const outlineColor = element . hasAttribute ( GLOBALS . DATA_BRACKETS_ID_ATTR ) ? "#4285F4" : "#3C3F41" ;
728696 element . style . outline = `1px solid ${ outlineColor } ` ;
729697
730- // Only apply background tint for editable elements (not for dynamic/read-only)
731- if ( element . hasAttribute ( GLOBALS . DATA_BRACKETS_ID_ATTR ) ) {
732- if ( element . _originalBackgroundColor === undefined ) {
733- element . _originalBackgroundColor = element . style . backgroundColor ;
734- }
735- element . style . backgroundColor = "rgba(0, 162, 255, 0.2)" ;
736- }
737-
738698 if ( ! _clickHighlight ) {
739699 _clickHighlight = new Highlight ( "#cfc" ) ;
740700 }
@@ -804,32 +764,12 @@ function RemoteFunctions(config = {}) {
804764 } ) ;
805765 }
806766
807- // call the selectElement as selectElement handles all the highlighting/boxes and all UI related stuff
808- selectElement ( element ) ;
809- brieflyDisableHoverListeners ( ) ;
810- }
811-
812- function onKeyUp ( event ) {
813- if ( _setup && ! _validEvent ( event ) ) {
814- window . document . removeEventListener ( "keyup" , onKeyUp ) ;
815- window . document . removeEventListener ( "mouseover" , onMouseOver ) ;
816- window . document . removeEventListener ( "mouseout" , onMouseOut ) ;
817- window . document . removeEventListener ( "mousemove" , onMouseMove ) ;
818- _localHighlight . clear ( ) ;
819- _localHighlight = undefined ;
820- _setup = false ;
821- }
822- }
823-
824- function onKeyDown ( event ) {
825- if ( ! _setup && _validEvent ( event ) ) {
826- window . document . addEventListener ( "keyup" , onKeyUp ) ;
827- window . document . addEventListener ( "mouseover" , onMouseOver ) ;
828- window . document . addEventListener ( "mouseout" , onMouseOut ) ;
829- window . document . addEventListener ( "mousemove" , onMouseMove ) ;
830- _localHighlight = new Highlight ( "#ecc" , true ) ;
831- _setup = true ;
767+ // we call the select element function only when the element is not editable (JS generated content)
768+ // because for editable elements, highlightRule function already calls selectElement internally
769+ if ( ! LivePreviewView . isElementEditable ( element ) ) {
770+ selectElement ( element ) ;
832771 }
772+ brieflyDisableHoverListeners ( ) ;
833773 }
834774
835775 // remove active highlights
@@ -870,13 +810,10 @@ function RemoteFunctions(config = {}) {
870810 }
871811
872812 // select the first valid highlighted element
873- var foundValidElement = false ;
813+ let foundValidElement = false ;
874814 for ( i = 0 ; i < nodes . length ; i ++ ) {
875815 if ( LivePreviewView . isElementInspectable ( nodes [ i ] , true ) && nodes [ i ] . tagName !== "BR" ) {
876- // only call selectElement if it's a different element to avoid unnecessary box recreation
877- if ( previouslyClickedElement !== nodes [ i ] ) {
878- selectElement ( nodes [ i ] ) ;
879- }
816+ selectElement ( nodes [ i ] ) ;
880817 foundValidElement = true ;
881818 break ;
882819 }
@@ -1256,16 +1193,7 @@ function RemoteFunctions(config = {}) {
12561193 * when config is changed we clear all the highlighting and stuff
12571194 */
12581195 function _handleConfigurationChange ( ) {
1259- if ( _hoverHighlight ) {
1260- _hoverHighlight . clear ( ) ;
1261- }
1262- cleanupPreviousElementState ( ) ;
1263- const allElements = window . document . querySelectorAll ( `[${ GLOBALS . DATA_BRACKETS_ID_ATTR } ]` ) ;
1264- for ( let i = 0 ; i < allElements . length ; i ++ ) {
1265- if ( allElements [ i ] . _originalBackgroundColor !== undefined ) {
1266- clearElementBackground ( allElements [ i ] ) ;
1267- }
1268- }
1196+ hideHighlight ( ) ;
12691197 dismissUIAndCleanupState ( ) ;
12701198 }
12711199
@@ -1280,24 +1208,18 @@ function RemoteFunctions(config = {}) {
12801208 previouslyClickedElement . style . outline = "" ;
12811209 }
12821210 delete previouslyClickedElement . _originalOutline ;
1211+ previouslyClickedElement = null ;
1212+ }
12831213
1284- clearElementBackground ( previouslyClickedElement ) ;
1285- if ( _hoverHighlight ) {
1286- _hoverHighlight . clear ( ) ;
1287- }
1288- if ( _clickHighlight ) {
1289- _clickHighlight . clear ( ) ;
1290- _clickHighlight = null ;
1291- }
1214+ if ( config . mode === 'edit' ) {
1215+ hideHighlight ( ) ;
12921216
12931217 // Notify handlers about cleanup
12941218 getAllToolHandlers ( ) . forEach ( handler => {
12951219 if ( handler . onElementCleanup ) {
12961220 handler . onElementCleanup ( ) ;
12971221 }
12981222 } ) ;
1299-
1300- previouslyClickedElement = null ;
13011223 }
13021224 }
13031225
@@ -1316,7 +1238,6 @@ function RemoteFunctions(config = {}) {
13161238 function registerHandlers ( ) {
13171239 hideHighlight ( ) ; // clear previous highlighting
13181240 disableHoverListeners ( ) ; // Always remove existing listeners first to avoid duplicates
1319- window . document . removeEventListener ( "keydown" , onKeyDown ) ;
13201241 getAllToolHandlers ( ) . forEach ( handler => {
13211242 if ( handler . unregisterInteractionBlocker ) {
13221243 handler . unregisterInteractionBlocker ( ) ;
@@ -1332,7 +1253,6 @@ function RemoteFunctions(config = {}) {
13321253
13331254 // register the event handlers
13341255 enableHoverListeners ( ) ;
1335- window . document . addEventListener ( "keydown" , onKeyDown ) ;
13361256
13371257 // this is to block all the interactions of the user created elements
13381258 // so that lets say user created link doesn't redirect in edit mode
0 commit comments