Skip to content

Commit 4e62c3f

Browse files
devvaannshabose
authored andcommitted
fix: live preview edit working unexpectedly on popped out live previews
1 parent 5a59648 commit 4e62c3f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,6 +3894,9 @@ function RemoteFunctions(config = {}) {
38943894

38953895
function enableHoverListeners() {
38963896
if (config.isProUser && (config.highlight || shouldShowHighlightOnHover())) {
3897+
window.document.removeEventListener("mouseover", onElementHover);
3898+
window.document.removeEventListener("mouseout", onElementHoverOut);
3899+
38973900
window.document.addEventListener("mouseover", onElementHover);
38983901
window.document.addEventListener("mouseout", onElementHoverOut);
38993902
}
@@ -4693,6 +4696,37 @@ function RemoteFunctions(config = {}) {
46934696
cleanupPreviousElementState();
46944697
}
46954698

4699+
/**
4700+
* this is a hard reset function, it resets every live preview edit thing, whether it be UI boxes
4701+
* highlighting, any timers or anything
4702+
*/
4703+
function resetState() {
4704+
_stopAutoScroll();
4705+
4706+
if (_hoverHighlight) {
4707+
_hoverHighlight.clear();
4708+
_hoverHighlight = null;
4709+
}
4710+
if (_clickHighlight) {
4711+
_clickHighlight.clear();
4712+
_clickHighlight = null;
4713+
}
4714+
4715+
dismissUIAndCleanupState();
4716+
4717+
const allElements = window.document.querySelectorAll("[data-brackets-id]");
4718+
for (let i = 0; i < allElements.length; i++) {
4719+
if (allElements[i]._originalBackgroundColor !== undefined) {
4720+
clearElementBackground(allElements[i]);
4721+
}
4722+
}
4723+
4724+
if (config.isProUser) {
4725+
_hoverHighlight = new Highlight("#c8f9c5", true);
4726+
_clickHighlight = new Highlight("#cfc", true);
4727+
}
4728+
}
4729+
46964730

46974731
/**
46984732
* This function is responsible to move the cursor to the end of the text content when we start editing
@@ -4816,6 +4850,16 @@ function RemoteFunctions(config = {}) {
48164850
_editHandler = new DOMEditHandler(window.document);
48174851

48184852
function registerHandlers() {
4853+
// clear previous highlighting
4854+
if (_hoverHighlight) {
4855+
_hoverHighlight.clear();
4856+
_hoverHighlight = null;
4857+
}
4858+
if (_clickHighlight) {
4859+
_clickHighlight.clear();
4860+
_clickHighlight = null;
4861+
}
4862+
48194863
// Always remove existing listeners first to avoid duplicates
48204864
window.document.removeEventListener("mouseover", onElementHover);
48214865
window.document.removeEventListener("mouseout", onElementHoverOut);
@@ -4862,6 +4906,7 @@ function RemoteFunctions(config = {}) {
48624906
"finishEditing" : finishEditing,
48634907
"hasVisibleLivePreviewBoxes" : hasVisibleLivePreviewBoxes,
48644908
"dismissUIAndCleanupState" : dismissUIAndCleanupState,
4909+
"resetState" : resetState,
48654910
"enableHoverListeners" : enableHoverListeners,
48664911
"registerHandlers" : registerHandlers,
48674912
"handleDownloadEvent" : handleDownloadEvent

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ define(function (require, exports, module) {
435435
const urlString = `${url.origin}${url.pathname}`;
436436
if (_liveDocument && urlString === _resolveUrl(_liveDocument.doc.file.fullPath)) {
437437
_setStatus(STATUS_ACTIVE);
438+
resetLPEditState();
438439
}
439440
}
440441
Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "connect",
@@ -737,6 +738,17 @@ define(function (require, exports, module) {
737738
}
738739
}
739740

741+
/**
742+
* this function is to completely reset the live preview edit
743+
* its done so that when live preview is opened/popped out, we can re-update the config so that
744+
* there are no stale markers and edit works perfectly
745+
*/
746+
function resetLPEditState() {
747+
if (_protocol) {
748+
_protocol.evaluate("_LD.resetState()");
749+
}
750+
}
751+
740752
/**
741753
* Originally unload and reload agents. It doesn't apply for this new implementation.
742754
* @return {jQuery.Promise} Already resolved promise.

0 commit comments

Comments
 (0)