Skip to content

Commit 87f8f77

Browse files
committed
fix: svg elements drag-drop not ending on escape key press
1 parent 12608cb commit 87f8f77

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4561,6 +4561,44 @@ function RemoteFunctions(config = {}) {
45614561
window.document.removeEventListener("mousemove", onMouseMove);
45624562
}
45634563

4564+
/**
4565+
* This function is to end the svg drag drop when escape key is pressed if its currently active
4566+
* note: onMouseOut normally handles when a drop operation completes for svg elements
4567+
* but for escape key handling (cancelling the drag-drop) onMouseOut will not work as it expects the event param,
4568+
* but since the escape key handler is handled in phoenix-pro/main.js, so we cannot pass any events from there.
4569+
* that's the reason we need this function
4570+
*
4571+
* Also this is only for svgs as normal HTML elements uses draggable attribute and drag listeners
4572+
* so browsers automatically handle the escape key
4573+
*/
4574+
function cancelSVGDragIfActive() {
4575+
// check if any element is being dragged
4576+
if (!window._isDraggingSVG || !window._currentDraggedElement) {
4577+
return;
4578+
}
4579+
4580+
// clear the last highlighted element's background
4581+
if (_lastDragTarget) {
4582+
if (_lastDragTarget._originalDragBackgroundColor !== undefined) {
4583+
_lastDragTarget.style.backgroundColor = _lastDragTarget._originalDragBackgroundColor;
4584+
delete _lastDragTarget._originalDragBackgroundColor;
4585+
}
4586+
if (_lastDragTarget._originalDragOutline !== undefined) {
4587+
_lastDragTarget.style.outline = _lastDragTarget._originalDragOutline;
4588+
delete _lastDragTarget._originalDragOutline;
4589+
}
4590+
}
4591+
4592+
// revert everything back
4593+
_clearDropMarkers();
4594+
_stopAutoScroll();
4595+
_dragEndChores(window._currentDraggedElement);
4596+
delete window._currentDraggedElement;
4597+
delete window._isDraggingSVG;
4598+
_lastDragTarget = null;
4599+
_lastDropZone = null;
4600+
}
4601+
45644602
// helper function to get the current elements highlight mode
45654603
// this is as per user settings (either click or hover)
45664604
function getHighlightMode() {
@@ -5922,6 +5960,7 @@ function RemoteFunctions(config = {}) {
59225960
"finishEditing" : finishEditing,
59235961
"dismissUIAndCleanupState" : dismissUIAndCleanupState,
59245962
"handleDownloadEvent" : handleDownloadEvent,
5925-
"showToastMessage" : showToastMessage
5963+
"showToastMessage" : showToastMessage,
5964+
"cancelSVGDragIfActive" : cancelSVGDragIfActive
59265965
};
59275966
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Proprietary code, all rights reserved.
44
*/
55

6-
/*global customReturns, enableHoverListeners, dismissUIAndCleanupState*/
6+
/*global customReturns, enableHoverListeners, dismissUIAndCleanupState, cancelSVGDragIfActive */
77

88
function dismissLivePreviewEditBoxes() {
99
enableHoverListeners(); // so that if hover lock is there it will get cleared
1010
dismissUIAndCleanupState();
11+
cancelSVGDragIfActive(); // read this function's jsdoc to understand why its here
1112
}
1213

1314
customReturns.dismissLivePreviewEditBoxes = dismissLivePreviewEditBoxes;

0 commit comments

Comments
 (0)