Skip to content

Commit d851f1d

Browse files
committed
fix: live preview not handling escape keypress when highlight pref is on
1 parent b089bc2 commit d851f1d

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,19 +1847,32 @@ function RemoteFunctions(config) {
18471847
return JSON.stringify(config);
18481848
}
18491849

1850+
/**
1851+
* This function checks if there are any live preview boxes currently visible
1852+
* @return {boolean} true if any boxes are visible, false otherwise
1853+
*/
1854+
function hasVisibleLivePreviewBoxes() {
1855+
return _nodeMoreOptionsBox !== null || _nodeInfoBox !== null || previouslyClickedElement !== null;
1856+
}
1857+
18501858
/**
18511859
* This function is responsible to remove the more options box
18521860
* we do this either when user presses the Esc key or clicks on the HTML or Body tags
1861+
* @return {boolean} true if any boxes were dismissed, false otherwise
18531862
*/
18541863
function dismissMoreOptionsBox() {
1864+
let dismissed = false;
1865+
18551866
if (_nodeMoreOptionsBox) {
18561867
_nodeMoreOptionsBox.remove();
18571868
_nodeMoreOptionsBox = null;
1869+
dismissed = true;
18581870
}
18591871

18601872
if (_nodeInfoBox) {
18611873
_nodeInfoBox.remove();
18621874
_nodeInfoBox = null;
1875+
dismissed = true;
18631876
}
18641877

18651878
if (previouslyClickedElement) {
@@ -1870,7 +1883,10 @@ function RemoteFunctions(config) {
18701883
}
18711884
delete previouslyClickedElement._originalOutline;
18721885
previouslyClickedElement = null;
1886+
dismissed = true;
18731887
}
1888+
1889+
return dismissed;
18741890
}
18751891

18761892
// Function to handle direct editing of elements in the live preview
@@ -2037,6 +2053,8 @@ function RemoteFunctions(config) {
20372053
"getSimpleDOM" : getSimpleDOM,
20382054
"updateConfig" : updateConfig,
20392055
"startEditing" : startEditing,
2040-
"finishEditing" : finishEditing
2056+
"finishEditing" : finishEditing,
2057+
"dismissMoreOptionsBox" : dismissMoreOptionsBox,
2058+
"hasVisibleLivePreviewBoxes" : hasVisibleLivePreviewBoxes
20412059
};
20422060
}

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,25 @@ define(function (require, exports, module) {
699699
}
700700
}
701701

702+
/**
703+
* Check if live preview boxes are currently visible
704+
*/
705+
function hasVisibleLivePreviewBoxes() {
706+
if (_protocol) {
707+
return _protocol.evaluate("_LD.hasVisibleLivePreviewBoxes()");
708+
}
709+
return false;
710+
}
711+
712+
/**
713+
* Dismiss live preview more options box and info box
714+
*/
715+
function dismissLivePreviewBoxes() {
716+
if (_protocol) {
717+
_protocol.evaluate("_LD.dismissMoreOptionsBox()");
718+
}
719+
}
720+
702721
/**
703722
* Originally unload and reload agents. It doesn't apply for this new implementation.
704723
* @return {jQuery.Promise} Already resolved promise.
@@ -765,6 +784,8 @@ define(function (require, exports, module) {
765784
exports.showHighlight = showHighlight;
766785
exports.hideHighlight = hideHighlight;
767786
exports.redrawHighlight = redrawHighlight;
787+
exports.hasVisibleLivePreviewBoxes = hasVisibleLivePreviewBoxes;
788+
exports.dismissLivePreviewBoxes = dismissLivePreviewBoxes;
768789
exports.init = init;
769790
exports.isActive = isActive;
770791
exports.setLivePreviewPinned= setLivePreviewPinned;

src/LiveDevelopment/main.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ define(function main(require, exports, module) {
4242
Strings = require("strings"),
4343
ExtensionUtils = require("utils/ExtensionUtils"),
4444
StringUtils = require("utils/StringUtils"),
45-
EventDispatcher = require("utils/EventDispatcher");
45+
EventDispatcher = require("utils/EventDispatcher"),
46+
WorkspaceManager = require("view/WorkspaceManager");
4647

4748
const EVENT_LIVE_HIGHLIGHT_PREF_CHANGED = "liveHighlightPrefChange";
4849

@@ -237,6 +238,19 @@ define(function main(require, exports, module) {
237238
}
238239
}
239240

241+
/**
242+
* this function handles escape key for live preview to hide boxes if they are visible
243+
* @param {Event} event
244+
*/
245+
function _handleLivePreviewEscapeKey(event) {
246+
// we only handle the escape keypress for live preview when its active
247+
if (MultiBrowserLiveDev.status === MultiBrowserLiveDev.STATUS_ACTIVE) {
248+
MultiBrowserLiveDev.dismissLivePreviewBoxes();
249+
}
250+
// returning false to let the editor also handle the escape key
251+
return false;
252+
}
253+
240254
/** Initialize LiveDevelopment */
241255
AppInit.appReady(function () {
242256
params.parse();
@@ -291,6 +305,9 @@ define(function main(require, exports, module) {
291305
exports.trigger(exports.EVENT_LIVE_PREVIEW_RELOAD, clientDetails);
292306
});
293307

308+
// allow live preview to handle escape key event
309+
// Escape is mainly to hide boxes if they are visible
310+
WorkspaceManager.addEscapeKeyEventHandler("livePreview", _handleLivePreviewEscapeKey);
294311
});
295312

296313
// init prefs

0 commit comments

Comments
 (0)