Skip to content

Commit 452af54

Browse files
committed
feat: make drag drop more intuitive
1 parent bda7133 commit 452af54

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ function RemoteFunctions(config = {}) {
375375
let DROP_MARKER_CLASSNAME = "__brackets-drop-marker-horizontal";
376376
let DROP_MARKER_VERTICAL_CLASSNAME = "__brackets-drop-marker-vertical";
377377
let DROP_MARKER_INSIDE_CLASSNAME = "__brackets-drop-marker-inside";
378+
let DROP_MARKER_ARROW_CLASSNAME = "__brackets-drop-marker-arrow";
378379

379380
/**
380381
* This function is responsible to determine whether to show vertical/horizontal indicators
@@ -790,6 +791,11 @@ function RemoteFunctions(config = {}) {
790791
// clean any existing marker from that element
791792
_removeDropMarkerFromElement(element);
792793

794+
if (element._originalDragBackgroundColor === undefined) {
795+
element._originalDragBackgroundColor = element.style.backgroundColor;
796+
}
797+
element.style.backgroundColor = "rgba(66, 133, 244, 0.15)";
798+
793799
// create the marker element
794800
let marker = window.document.createElement("div");
795801

@@ -806,6 +812,15 @@ function RemoteFunctions(config = {}) {
806812
marker.style.borderRadius = "2px";
807813
marker.style.pointerEvents = "none";
808814

815+
// for the arrow indicator
816+
let arrow = window.document.createElement("div");
817+
arrow.className = DROP_MARKER_ARROW_CLASSNAME;
818+
arrow.style.position = "fixed";
819+
arrow.style.zIndex = "2147483648";
820+
arrow.style.pointerEvents = "none";
821+
arrow.style.fontWeight = "bold";
822+
arrow.style.color = "#4285F4";
823+
809824
if (dropZone === "inside") {
810825
// inside marker - outline around the element
811826
marker.style.border = "2px dashed #4285F4";
@@ -814,40 +829,66 @@ function RemoteFunctions(config = {}) {
814829
marker.style.top = rect.top + "px";
815830
marker.style.width = rect.width + "px";
816831
marker.style.height = rect.height + "px";
817-
marker.style.animation = "insideMarkerPulse 1s ease-in-out infinite alternate";
832+
833+
// exclusive or symbol (plus inside circle) we use when dropping inside
834+
arrow.style.fontSize = "16px";
835+
arrow.innerHTML = "⊕";
836+
arrow.style.left = (rect.left + rect.width / 2) + "px";
837+
arrow.style.top = (rect.top + rect.height / 2) + "px";
838+
arrow.style.transform = "translate(-50%, -50%)";
818839
} else {
819840
// Before/After markers - lines
820841
marker.style.background = "linear-gradient(90deg, #4285F4, #1976D2)";
821842
marker.style.boxShadow = "0 0 8px rgba(66, 133, 244, 0.5)";
822-
marker.style.animation = "dropMarkerPulse 0.8s ease-in-out infinite alternate";
823843

844+
arrow.style.fontSize = "22px";
824845
if (indicatorType === "vertical") {
825846
// Vertical marker (for flex row containers)
826847
marker.style.width = "3px";
827848
marker.style.height = rect.height + "px";
828849
marker.style.top = rect.top + "px";
850+
arrow.style.top = (rect.top + rect.height / 2) + "px";
829851

830852
if (dropZone === "after") {
831853
marker.style.left = rect.right + 3 + "px";
854+
// Right arrow
855+
arrow.innerHTML = "→";
856+
arrow.style.left = (rect.right + 5) + "px";
857+
arrow.style.transform = "translateY(-50%)";
832858
} else {
833859
marker.style.left = rect.left - 5 + "px";
860+
// Left arrow
861+
arrow.innerHTML = "←";
862+
arrow.style.left = (rect.left - 15) + "px";
863+
arrow.style.transform = "translate(-50%, -50%)";
834864
}
835865
} else {
836866
// Horizontal marker (for block/grid containers)
837867
marker.style.width = rect.width + "px";
838868
marker.style.height = "3px";
839869
marker.style.left = rect.left + "px";
870+
arrow.style.left = (rect.left + rect.width / 2) + "px";
840871

841872
if (dropZone === "after") {
842873
marker.style.top = rect.bottom + 3 + "px";
874+
// Down arrow
875+
arrow.innerHTML = "↓";
876+
arrow.style.top = rect.bottom + "px";
877+
arrow.style.transform = "translateX(-50%)";
843878
} else {
844879
marker.style.top = rect.top - 5 + "px";
880+
// Up arrow
881+
arrow.innerHTML = "↑";
882+
arrow.style.top = (rect.top - 15) + "px";
883+
arrow.style.transform = "translate(-50%, -50%)";
845884
}
846885
}
847886
}
848887

849888
element._dropMarker = marker; // we need this in the _removeDropMarkerFromElement function
889+
element._dropArrow = arrow; // store arrow reference too
850890
window.document.body.appendChild(marker);
891+
window.document.body.appendChild(arrow);
851892
}
852893

853894
/**
@@ -859,6 +900,10 @@ function RemoteFunctions(config = {}) {
859900
element._dropMarker.parentNode.removeChild(element._dropMarker);
860901
delete element._dropMarker;
861902
}
903+
if (element._dropArrow && element._dropArrow.parentNode) {
904+
element._dropArrow.parentNode.removeChild(element._dropArrow);
905+
delete element._dropArrow;
906+
}
862907
}
863908

864909
/**
@@ -869,6 +914,7 @@ function RemoteFunctions(config = {}) {
869914
let horizontalMarkers = window.document.querySelectorAll("." + DROP_MARKER_CLASSNAME);
870915
let verticalMarkers = window.document.querySelectorAll("." + DROP_MARKER_VERTICAL_CLASSNAME);
871916
let insideMarkers = window.document.querySelectorAll("." + DROP_MARKER_INSIDE_CLASSNAME);
917+
let arrows = window.document.querySelectorAll("." + DROP_MARKER_ARROW_CLASSNAME);
872918

873919
for (let i = 0; i < horizontalMarkers.length; i++) {
874920
if (horizontalMarkers[i].parentNode) {
@@ -888,10 +934,17 @@ function RemoteFunctions(config = {}) {
888934
}
889935
}
890936

937+
for (let i = 0; i < arrows.length; i++) {
938+
if (arrows[i].parentNode) {
939+
arrows[i].parentNode.removeChild(arrows[i]);
940+
}
941+
}
942+
891943
// Also clear any element references
892944
let elements = window.document.querySelectorAll("[data-brackets-id]");
893945
for (let j = 0; j < elements.length; j++) {
894946
delete elements[j]._dropMarker;
947+
delete elements[j]._dropArrow;
895948
// only restore the styles that were modified by drag operations
896949
if (elements[j]._originalDragBackgroundColor !== undefined) {
897950
elements[j].style.backgroundColor = elements[j]._originalDragBackgroundColor;

0 commit comments

Comments
 (0)