MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / startDrag

Function startDrag

src/handlers/editorFileTab.js:89–152  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

87 * @param {MouseEvent} e
88 */
89export default function startDrag(e) {
90 const { clientX, clientY } = getClientPos(e);
91 const { editor, activeFile } = editorManager;
92
93 if (activeFile.focusedBefore) {
94 editor.focus();
95 }
96
97 if (settings.value.vibrateOnTap) {
98 navigator.vibrate(config.VIBRATION_TIME);
99 }
100
101 $tab = e.target;
102 $parent = $tab.parentElement;
103 $tabClone = $tab.cloneNode(true);
104 initialNextSibling = $tab.nextElementSibling;
105 didReorder = false;
106
107 const rect = $tab.getBoundingClientRect();
108 const parentRect = $parent.getBoundingClientRect();
109
110 /**
111 * Setting offset of tab from pointer
112 * this is used to set the position of tab when dragging
113 * so tab moves with pointer but not snapped to top left corner
114 * of the tab because setting translate will move the tab to
115 * clientX, clientY position, it's like virtual transform origin.
116 *
117 * (rect.x, rect.y) is the position of the tab
118 * __________________
119 * | * (pointer) | clientY - rect.y
120 * |__________________|
121 * <----> clientX - rect.x
122 */
123 offsetX = clientX - rect.x;
124 offsetY = clientY - rect.y;
125
126 tabLeft = rect.left;
127 tabWidth = rect.width;
128 parentLeft = parentRect.left;
129 parentRight = parentRect.right;
130
131 MAX_SCROLL = $parent.scrollWidth - parentRect.width;
132 MIN_SCROLL = 0;
133
134 // setup the cloned tab
135 $tabClone.classList.add("drag");
136 $tabClone.style.height = `${rect.height}px`;
137 $tabClone.style.width = `${rect.width}px`;
138 $tabClone.style.transform = `translate3d(${rect.x}px, ${rect.y}px, 0)`;
139 $tab.style.opacity = "0.35";
140 app.append($tabClone);
141 $tab.click();
142
143 document.addEventListener("mousemove", onDrag, opts);
144 document.addEventListener("touchmove", onDrag, opts);
145 document.addEventListener("mouseup", releaseDrag, opts);
146 document.addEventListener("touchend", releaseDrag, opts);

Callers 1

openFile.jsFile · 0.85

Calls 4

getClientPosFunction · 0.85
focusMethod · 0.80
addMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected