Skip to content

Commit 7c6b481

Browse files
committed
fix: info box disappearing when elements selection set to click mode
1 parent ad89b0d commit 7c6b481

File tree

1 file changed

+41
-49
lines changed

1 file changed

+41
-49
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,9 +2308,9 @@ function RemoteFunctions(config = {}) {
23082308
if (_hoverHighlight && shouldShowHighlightOnHover()) {
23092309
_hoverHighlight.clear();
23102310
clearElementBackground(element);
2311+
dismissNodeInfoBox();
23112312
}
23122313
}
2313-
dismissNodeInfoBox();
23142314
}
23152315

23162316
/**
@@ -2833,71 +2833,63 @@ function RemoteFunctions(config = {}) {
28332833
}
28342834

28352835
function updateConfig(newConfig) {
2836-
var oldConfig = config;
2836+
const oldConfig = config;
28372837
config = JSON.parse(newConfig);
28382838

2839-
if (config.highlight || (config.isProUser && shouldShowHighlightOnHover())) {
2840-
// Add hover event listeners if highlight is enabled OR editHighlights is set to hover
2841-
window.document.removeEventListener("mouseover", onElementHover);
2842-
window.document.removeEventListener("mouseout", onElementHoverOut);
2843-
window.document.addEventListener("mouseover", onElementHover);
2844-
window.document.addEventListener("mouseout", onElementHoverOut);
2845-
} else {
2846-
// Remove hover event listeners only if both highlight is disabled AND editHighlights is not set to hover
2847-
window.document.removeEventListener("mouseover", onElementHover);
2848-
window.document.removeEventListener("mouseout", onElementHoverOut);
2849-
2850-
// Remove info box and more options box if highlight is disabled
2851-
dismissNodeInfoBox();
2852-
dismissNodeMoreOptionsBox();
2853-
}
2854-
2855-
// Handle element highlight mode changes for instant switching
2839+
// Determine if configuration has changed significantly
28562840
const oldHighlightMode = oldConfig.elemHighlights ? oldConfig.elemHighlights.toLowerCase() : "hover";
28572841
const newHighlightMode = getHighlightMode();
2842+
const highlightModeChanged = oldHighlightMode !== newHighlightMode;
2843+
const isProStatusChanged = oldConfig.isProUser !== config.isProUser;
2844+
const highlightSettingChanged = oldConfig.highlight !== config.highlight;
28582845

2859-
if (oldHighlightMode !== newHighlightMode) {
2860-
// Clear any existing highlights when mode changes
2861-
if (_hoverHighlight) {
2862-
_hoverHighlight.clear();
2863-
}
2864-
2865-
// Clean up any previously highlighted elements
2866-
if (previouslyClickedElement) {
2867-
clearElementBackground(previouslyClickedElement);
2868-
}
2869-
2870-
// Clear all elements that might have hover background styling applied
2871-
const allElements = window.document.querySelectorAll("[data-brackets-id]");
2872-
for (let i = 0; i < allElements.length; i++) {
2873-
if (allElements[i]._originalBackgroundColor !== undefined) {
2874-
clearElementBackground(allElements[i]);
2875-
}
2876-
}
2846+
// Handle significant configuration changes
2847+
if (highlightModeChanged || isProStatusChanged || highlightSettingChanged) {
2848+
_handleConfigurationChange();
2849+
}
2850+
_updateEventListeners();
28772851

2878-
// Remove info box when switching modes to avoid confusion
2879-
if (_nodeInfoBox && !_nodeMoreOptionsBox) {
2880-
dismissNodeInfoBox();
2881-
}
2852+
return JSON.stringify(config);
2853+
}
28822854

2883-
// Re-setup event listeners based on new mode to ensure proper behavior
2884-
if (config.highlight && config.isProUser) {
2885-
window.document.removeEventListener("mouseover", onElementHover);
2886-
window.document.removeEventListener("mouseout", onElementHoverOut);
2887-
window.document.addEventListener("mouseover", onElementHover);
2888-
window.document.addEventListener("mouseout", onElementHoverOut);
2855+
/**
2856+
* when config is changed we clear all the highlighting and stuff
2857+
*/
2858+
function _handleConfigurationChange() {
2859+
if (_hoverHighlight) {
2860+
_hoverHighlight.clear();
2861+
}
2862+
cleanupPreviousElementState();
2863+
const allElements = window.document.querySelectorAll("[data-brackets-id]");
2864+
for (let i = 0; i < allElements.length; i++) {
2865+
if (allElements[i]._originalBackgroundColor !== undefined) {
2866+
clearElementBackground(allElements[i]);
28892867
}
28902868
}
2869+
dismissUIAndCleanupState();
2870+
}
28912871

2892-
return JSON.stringify(config);
2872+
/**
2873+
* Update event listeners based on current configuration
2874+
*/
2875+
function _updateEventListeners() {
2876+
window.document.removeEventListener("mouseover", onElementHover);
2877+
window.document.removeEventListener("mouseout", onElementHoverOut);
2878+
if (config.highlight || (config.isProUser && shouldShowHighlightOnHover())) {
2879+
window.document.addEventListener("mouseover", onElementHover);
2880+
window.document.addEventListener("mouseout", onElementHoverOut);
2881+
}
28932882
}
28942883

28952884
/**
28962885
* This function checks if there are any live preview boxes currently visible
28972886
* @return {boolean} true if any boxes are visible, false otherwise
28982887
*/
28992888
function hasVisibleLivePreviewBoxes() {
2900-
return _nodeMoreOptionsBox !== null || _nodeInfoBox !== null || _aiPromptBox !== null || previouslyClickedElement !== null;
2889+
return _nodeMoreOptionsBox !== null ||
2890+
_nodeInfoBox !== null ||
2891+
_aiPromptBox !== null ||
2892+
previouslyClickedElement !== null;
29012893
}
29022894

29032895
/**

0 commit comments

Comments
 (0)