Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/LiveDevelopment/BrowserScripts/RemoteFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,13 @@
}

const element = event.target;
if(!LivePreviewView.isElementInspectable(element) || element.nodeType !== Node.ELEMENT_NODE) {
return;
}

// Same element as last hover — nothing changed, skip entirely
if (element === _lastHoverTarget) {
return;
}
if(!LivePreviewView.isElementInspectable(element) || element.nodeType !== Node.ELEMENT_NODE) {
return;
}
_lastHoverTarget = element;

// if _hoverHighlight is uninitialized, initialize it
Expand All @@ -615,21 +614,30 @@
}
}

function onElementHoverOut(event) {
// don't want highlighting and stuff when auto scrolling
if (SHARED_STATE.isAutoScrolling) { return; }
function _clearHoverState() {
if (SHARED_STATE.isAutoScrolling) {
return;
}
if (_hoverHighlight && shouldShowHighlightOnHover()) {
_lastHoverTarget = null;
_scheduleHoverUpdate();
}
}

function onElementHoverOut(event) {
const element = event.target;
// Use isElementInspectable (not isElementEditable) so that JS-rendered
// elements also get their hover highlight and hover box properly dismissed.
if(LivePreviewView.isElementInspectable(element) && element.nodeType === Node.ELEMENT_NODE) {
if (_hoverHighlight && shouldShowHighlightOnHover()) {
_lastHoverTarget = null;
_scheduleHoverUpdate();
}
_clearHoverState();
}
}

// for popped out window: the in-panel iframe case is forwarded parent-side via _LD.clearHoverState().
function onDocumentMouseLeave() {
_clearHoverState();
}

function scrollElementToViewPort(element) {
if (!element) {
return;
Expand Down Expand Up @@ -711,7 +719,9 @@

function disableHoverListeners() {
window.document.removeEventListener("mouseover", onElementHover);
window.document.removeEventListener("mousemove", onElementHover);

Check warning on line 722 in src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ54ZAcCoRufhO6yg3dy&open=AZ54ZAcCoRufhO6yg3dy&pullRequest=2958
window.document.removeEventListener("mouseout", onElementHoverOut);
window.document.documentElement.removeEventListener("mouseleave", onDocumentMouseLeave);

Check warning on line 724 in src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ54ZAcCoRufhO6yg3dz&open=AZ54ZAcCoRufhO6yg3dz&pullRequest=2958
// Cancel any pending rAF hover update so stale callbacks don't fire
if (_pendingHoverRAF) {
cancelAnimationFrame(_pendingHoverRAF);
Expand All @@ -732,7 +742,9 @@
if (config.mode === 'edit' && shouldShowHighlightOnHover()) {
disableHoverListeners();
window.document.addEventListener("mouseover", onElementHover);
window.document.addEventListener("mousemove", onElementHover);

Check warning on line 745 in src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ54ZAcCoRufhO6yg3d0&open=AZ54ZAcCoRufhO6yg3d0&pullRequest=2958
window.document.addEventListener("mouseout", onElementHoverOut);
window.document.documentElement.addEventListener("mouseleave", onDocumentMouseLeave);

Check warning on line 747 in src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ54ZAcCoRufhO6yg3d1&open=AZ54ZAcCoRufhO6yg3d1&pullRequest=2958
}
}

Expand Down Expand Up @@ -1714,7 +1726,8 @@
"getHighlightCount": getHighlightCount,
"getHighlightTrackingElement": getHighlightTrackingElement,
"getHighlightStyle": getHighlightStyle,
"setHotCornerHidden": setHotCornerHidden
"setHotCornerHidden": setHotCornerHidden,
"clearHoverState": _clearHoverState
};

// the below code comment is replaced by added scripts for extensibility
Expand Down
11 changes: 11 additions & 0 deletions src/LiveDevelopment/LiveDevMultiBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,16 @@ define(function (require, exports, module) {
}
}

/**
* Clear hover highlight and hover box in the preview. Forwarded from the parent because the
* previewed iframe does not reliably receive mouseout/mouseleave on a slow pointer exit.
*/
function clearHoverState() {
if (_protocol) {
_protocol.evaluate("_LD.clearHoverState && _LD.clearHoverState()");
}
}

/**
* Update configuration in the remote browser
*/
Expand Down Expand Up @@ -860,6 +870,7 @@ define(function (require, exports, module) {
exports.showHighlight = showHighlight;
exports.hideHighlight = hideHighlight;
exports.redrawHighlight = redrawHighlight;
exports.clearHoverState = clearHoverState;
exports.getConfig = getConfig;
exports.updateConfig = updateConfig;
exports.refreshConfig = refreshConfig;
Expand Down
5 changes: 5 additions & 0 deletions src/extensionsIntegrated/Phoenix-live-preview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,11 @@ define(function (require, exports, module) {
$panel.find(".custom-server-banner-close-icon").on("click", ()=>{
$panel.find(".live-preview-custom-banner").addClass("forced-hidden");
});
// The previewed iframe does not reliably fire mouseout/mouseleave on a slow pointer exit,
// leaving the hover highlight/box stuck. Detect the leave parent-side and forward a clear.
$panel.on("mouseleave", "#panel-live-preview-frame", function () {
MultiBrowserLiveDev.clearHoverState();
});
$iframe[0].onload = function () {
$iframe.attr('srcdoc', null);
};
Expand Down
Loading