Skip to content

Commit 9acfcb7

Browse files
committed
fix: element highlights setting not getting applied immediately directly
1 parent 911226e commit 9acfcb7

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,22 +1944,25 @@ function RemoteFunctions(config) {
19441944
// init
19451945
_editHandler = new DOMEditHandler(window.document);
19461946

1947-
if (config.isLPEditFeaturesActive) {
1948-
// Initialize hover highlight with Chrome-like colors
1949-
_hoverHighlight = new Highlight("#c8f9c5", true); // Green similar to Chrome's padding color
1950-
1951-
// Initialize click highlight with animation
1952-
_clickHighlight = new Highlight("#cfc", true); // Light green for click highlight
1953-
1954-
window.document.addEventListener("mouseover", onElementHover);
1955-
window.document.addEventListener("mouseout", onElementHoverOut);
1956-
window.document.addEventListener("click", onClick);
1957-
window.document.addEventListener("dblclick", onDoubleClick);
1958-
window.document.addEventListener("dragover", onDragOver);
1959-
window.document.addEventListener("drop", onDrop);
1960-
window.document.addEventListener("keydown", onKeyDown);
1947+
function registerHandlers() {
1948+
if (config.isLPEditFeaturesActive) {
1949+
// Initialize hover highlight with Chrome-like colors
1950+
_hoverHighlight = new Highlight("#c8f9c5", true); // Green similar to Chrome's padding color
1951+
1952+
// Initialize click highlight with animation
1953+
_clickHighlight = new Highlight("#cfc", true); // Light green for click highlight
1954+
1955+
window.document.addEventListener("mouseover", onElementHover);
1956+
window.document.addEventListener("mouseout", onElementHoverOut);
1957+
window.document.addEventListener("click", onClick);
1958+
window.document.addEventListener("dblclick", onDoubleClick);
1959+
window.document.addEventListener("dragover", onDragOver);
1960+
window.document.addEventListener("drop", onDrop);
1961+
window.document.addEventListener("keydown", onKeyDown);
1962+
}
19611963
}
19621964

1965+
registerHandlers();
19631966

19641967
return {
19651968
"DOMEditHandler" : DOMEditHandler,
@@ -1973,6 +1976,7 @@ function RemoteFunctions(config) {
19731976
"startEditing" : startEditing,
19741977
"finishEditing" : finishEditing,
19751978
"dismissMoreOptionsBox" : dismissMoreOptionsBox,
1976-
"hasVisibleLivePreviewBoxes" : hasVisibleLivePreviewBoxes
1979+
"hasVisibleLivePreviewBoxes" : hasVisibleLivePreviewBoxes,
1980+
"registerHandlers" : registerHandlers
19771981
};
19781982
}

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,24 @@ define(function (require, exports, module) {
718718
}
719719
}
720720

721+
/**
722+
* Register event handlers in the remote browser for live preview functionality
723+
*/
724+
function registerHandlers() {
725+
if (_protocol) {
726+
_protocol.evaluate("_LD.registerHandlers()");
727+
}
728+
}
729+
730+
/**
731+
* Update configuration in the remote browser
732+
*/
733+
function updateConfig(configJSON) {
734+
if (_protocol) {
735+
_protocol.evaluate("_LD.updateConfig('" + configJSON + "')");
736+
}
737+
}
738+
721739
/**
722740
* Originally unload and reload agents. It doesn't apply for this new implementation.
723741
* @return {jQuery.Promise} Already resolved promise.
@@ -786,6 +804,8 @@ define(function (require, exports, module) {
786804
exports.redrawHighlight = redrawHighlight;
787805
exports.hasVisibleLivePreviewBoxes = hasVisibleLivePreviewBoxes;
788806
exports.dismissLivePreviewBoxes = dismissLivePreviewBoxes;
807+
exports.registerHandlers = registerHandlers;
808+
exports.updateConfig = updateConfig;
789809
exports.init = init;
790810
exports.isActive = isActive;
791811
exports.setLivePreviewPinned= setLivePreviewPinned;

src/LiveDevelopment/main.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,18 @@ define(function main(require, exports, module) {
296296
.on("change", function () {
297297
config.remoteHighlight = prefs.get(PREF_REMOTEHIGHLIGHT);
298298
if (MultiBrowserLiveDev && MultiBrowserLiveDev.status >= MultiBrowserLiveDev.STATUS_ACTIVE) {
299-
MultiBrowserLiveDev.agents.remote.call("updateConfig",JSON.stringify(config));
299+
MultiBrowserLiveDev.updateConfig(JSON.stringify(config));
300300
}
301301
});
302302

303303
// this function is responsible to update element highlight config
304304
function updateElementHighlightConfig() {
305305
const prefValue = PreferencesManager.get(PREFERENCE_PROJECT_ELEMENT_HIGHLIGHT);
306306
config.elemHighlights = prefValue || "hover";
307+
if (MultiBrowserLiveDev && MultiBrowserLiveDev.status >= MultiBrowserLiveDev.STATUS_ACTIVE) {
308+
MultiBrowserLiveDev.updateConfig(JSON.stringify(config));
309+
MultiBrowserLiveDev.registerHandlers();
310+
}
307311
}
308312

309313
PreferencesManager.on("change", PREFERENCE_PROJECT_ELEMENT_HIGHLIGHT, function() {
@@ -335,7 +339,7 @@ define(function main(require, exports, module) {
335339
config.highlight = PreferencesManager.getViewState("livedevHighlight");
336340
_updateHighlightCheckmark();
337341
if (MultiBrowserLiveDev && MultiBrowserLiveDev.status >= MultiBrowserLiveDev.STATUS_ACTIVE) {
338-
MultiBrowserLiveDev.agents.remote.call("updateConfig",JSON.stringify(config));
342+
MultiBrowserLiveDev.updateConfig(JSON.stringify(config));
339343
}
340344
});
341345

0 commit comments

Comments
 (0)