Skip to content

Commit 202f5fb

Browse files
committed
chore: better generic event handling for escape key press in editor
1 parent be480c4 commit 202f5fb

File tree

5 files changed

+37
-46
lines changed

5 files changed

+37
-46
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ function RemoteFunctions(config = {}) {
9999
// called when an item is selected from the more options dropdown
100100
"handleDropdownClick",
101101
"reRegisterEventHandlers",
102-
"handleClick" // handle click on an icon in the more options box.
102+
"handleClick", // handle click on an icon in the more options box.
103+
// when escape key is presses in the editor, we may need to dismiss the live edit boxes.
104+
"handleEscapePressFromEditor"
103105
];
104106

105107
const _moreOptionsHandlers = new Map();
@@ -4312,6 +4314,16 @@ function RemoteFunctions(config = {}) {
43124314
});
43134315
}
43144316

4317+
function _escapeKeyPressInEditor() {
4318+
enableHoverListeners(); // so that if hover lock is there it will get cleared
4319+
dismissUIAndCleanupState();
4320+
getAllNodeMoreOptionsHandlers().forEach(handler => {
4321+
if (handler.handleEscapePressFromEditor) {
4322+
handler.handleEscapePressFromEditor();
4323+
}
4324+
});
4325+
}
4326+
43154327
function _requestConfigRefresh() {
43164328
// send image gallery state change message to editor to save preference in state manager
43174329
window._Brackets_MessageBroker.send({
@@ -4342,6 +4354,9 @@ function RemoteFunctions(config = {}) {
43424354
});
43434355

43444356
let customReturns = {};
4357+
// only apis that needs to be called from phoenix js layer should be customReturns. APis that are shared within
4358+
// the remote function context only should not be in customReturns and should be in
4359+
// either SHARED_STATE for state vars, GLOBALS for global vars, or LivePreviewView for shared functions.
43454360
customReturns = { // we have to do this else the minifier will strip the customReturns variable
43464361
...customReturns,
43474362
"DOMEditHandler" : DOMEditHandler,
@@ -4356,7 +4371,8 @@ function RemoteFunctions(config = {}) {
43564371
"finishEditing" : finishEditing,
43574372
"dismissUIAndCleanupState" : dismissUIAndCleanupState,
43584373
"handleDownloadEvent" : handleDownloadEvent,
4359-
"showToastMessage" : showToastMessage
4374+
"showToastMessage" : showToastMessage,
4375+
"escapeKeyPressInEditor": _escapeKeyPressInEditor
43604376
};
43614377

43624378
// the below code comment is replaced by added scripts for extensibility

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ define(function (require, exports, module) {
8787
LivePreviewTransport = require("LiveDevelopment/MultiBrowserImpl/transports/LivePreviewTransport"),
8888
LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol"),
8989
Metrics = require("utils/Metrics"),
90+
WorkspaceManager = require("view/WorkspaceManager"),
9091
PageLoaderWorkerScript = require("text!LiveDevelopment/BrowserScripts/pageLoaderWorker.js");
9192

9293
// Documents
@@ -726,6 +727,23 @@ define(function (require, exports, module) {
726727
}
727728
}
728729

730+
731+
/**
732+
* this function handles escape key for live preview to hide boxes if they are visible
733+
* @param {Event} event
734+
*/
735+
function _handleLivePreviewEscapeKey(event) {
736+
const currLiveDoc = getCurrentLiveDoc();
737+
if (currLiveDoc && currLiveDoc.protocol && currLiveDoc.protocol.evaluate) {
738+
currLiveDoc.protocol.evaluate("_LD.escapeKeyPressInEditor()");
739+
}
740+
// returning false to let the editor also handle the escape key
741+
return false;
742+
}
743+
// allow live preview to handle escape key event
744+
// Escape is mainly to hide boxes if they are visible
745+
WorkspaceManager.addEscapeKeyEventHandler("livePreview", _handleLivePreviewEscapeKey);
746+
729747
/**
730748
* gets configuration used to set in the remote browser
731749
*/

src/extensionsIntegrated/phoenix-pro/browser-context/dragAndDrop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,5 +1364,5 @@ LivePreviewView.registerNodeMoreOptionsHandler("DragAndDrop", {
13641364
dismiss: ()=>{},
13651365
reRegisterEventHandlers: _reRegisterEventHandlers,
13661366
onElementSelected: _onElementSelected,
1367-
_proExtnDismissLivePreviewEditBoxes: cancelSVGDragIfActive
1367+
handleEscapePressFromEditor: cancelSVGDragIfActive
13681368
});

src/extensionsIntegrated/phoenix-pro/browser-context/remote-utils.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/extensionsIntegrated/phoenix-pro/main.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,11 @@ define(function (require, exports, module) {
1515
throw new Error("KernalModeTrust is not defined. Cannot boot without trust ring");
1616
}
1717

18-
const WorkspaceManager = require("view/WorkspaceManager"),
19-
LiveDevMultiBrowser = require("LiveDevelopment/LiveDevMultiBrowser");
20-
21-
const remoteUtilsCode = require("text!./browser-context/remote-utils.js");
2218
const HyperlinkEditorCode = require("text!./browser-context/hyperlink-editor.js");
2319
const RulerLinesCode = require("text!./browser-context/ruler-lines.js");
2420
const DragAndDropCode = require("text!./browser-context/dragAndDrop.js");
2521
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
2622

27-
/**
28-
* this function handles escape key for live preview to hide boxes if they are visible
29-
* @param {Event} event
30-
*/
31-
function _handleLivePreviewEscapeKey(event) {
32-
const currLiveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
33-
if (currLiveDoc && currLiveDoc.protocol && currLiveDoc.protocol.evaluate) {
34-
currLiveDoc.protocol.evaluate("_LD.dismissLivePreviewEditBoxes()");
35-
}
36-
// returning false to let the editor also handle the escape key
37-
return false;
38-
}
39-
// allow live preview to handle escape key event
40-
// Escape is mainly to hide boxes if they are visible
41-
WorkspaceManager.addEscapeKeyEventHandler("livePreview", _handleLivePreviewEscapeKey);
42-
4323
function _addRemoteScripts() {
4424
// the ordering here is important
4525
// constants first
@@ -51,7 +31,6 @@ define(function (require, exports, module) {
5131
`cssStyles = ${JSON.stringify(remoteStyles.cssStyles)};`);
5232

5333
// functions start here
54-
LiveDevProtocol.addRemoteFunctionScript("remoteUtilsCode", remoteUtilsCode);
5534
LiveDevProtocol.addRemoteFunctionScript("HyperlinkEditorCode", HyperlinkEditorCode);
5635
LiveDevProtocol.addRemoteFunctionScript("RulerLinesCode", RulerLinesCode);
5736
LiveDevProtocol.addRemoteFunctionScript("DragAndDrop", DragAndDropCode);

0 commit comments

Comments
 (0)