@@ -24,7 +24,9 @@ function RemoteFunctions(config = {}) {
2424 const MessageBroker = window . _Brackets_MessageBroker ; // to be used by plugins.
2525
2626 const SHARED_STATE = {
27- __description : "Use this to keep shared state for Live Preview Edit instead of window.*"
27+ __description : "Use this to keep shared state for Live Preview Edit instead of window.*" ,
28+ _suppressDOMEditDismissal : false ,
29+ _suppressDOMEditDismissalTimeout : null
2830 } ;
2931
3032 let _hoverHighlight ;
@@ -1257,10 +1259,13 @@ function RemoteFunctions(config = {}) {
12571259 this . rememberedNodes = { } ;
12581260
12591261 // this check makes sure that if the element is no more in the DOM then we remove it
1260- if ( previouslySelectedElement && ! previouslySelectedElement . isConnected ) {
1261- dismissUIAndCleanupState ( ) ;
1262- } else {
1263- redrawEverything ( ) ;
1262+ // skip this check if suppression is active (e.g., when some internal feature updates source)
1263+ if ( ! SHARED_STATE . _suppressDOMEditDismissal ) {
1264+ if ( previouslySelectedElement && ! previouslySelectedElement . isConnected ) {
1265+ dismissUIAndCleanupState ( ) ;
1266+ } else {
1267+ redrawEverything ( ) ;
1268+ }
12641269 }
12651270 } ;
12661271
@@ -1335,6 +1340,24 @@ function RemoteFunctions(config = {}) {
13351340 }
13361341 }
13371342
1343+ /**
1344+ * Temporarily suppress the DOM edit dismissal check in apply()
1345+ * Used when source is modified from UI panels to prevent
1346+ * the panel from being dismissed when the DOM is updated.
1347+ * @param {Number } durationMs - Duration in milliseconds to suppress (default 100)
1348+ */
1349+ function suppressDOMEditDismissal ( durationMs ) {
1350+ durationMs = durationMs || 100 ;
1351+ if ( SHARED_STATE . _suppressDOMEditDismissalTimeout ) {
1352+ clearTimeout ( SHARED_STATE . _suppressDOMEditDismissalTimeout ) ;
1353+ }
1354+ SHARED_STATE . _suppressDOMEditDismissal = true ;
1355+ SHARED_STATE . _suppressDOMEditDismissalTimeout = setTimeout ( function ( ) {
1356+ SHARED_STATE . _suppressDOMEditDismissal = false ;
1357+ SHARED_STATE . _suppressDOMEditDismissalTimeout = null ;
1358+ } , durationMs ) ;
1359+ }
1360+
13381361 /**
13391362 * This function dismisses all UI elements and cleans up application state
13401363 * Called when user presses Esc key, clicks on HTML/Body tags, or other dismissal events
@@ -1425,7 +1448,8 @@ function RemoteFunctions(config = {}) {
14251448 "updateConfig" : updateConfig ,
14261449 "dismissUIAndCleanupState" : dismissUIAndCleanupState ,
14271450 "escapeKeyPressInEditor" : _handleEscapeKeyPress ,
1428- "getMode" : function ( ) { return config . mode ; }
1451+ "getMode" : function ( ) { return config . mode ; } ,
1452+ "suppressDOMEditDismissal" : suppressDOMEditDismissal
14291453 } ;
14301454
14311455 // the below code comment is replaced by added scripts for extensibility
0 commit comments