MCPcopy
hub / github.com/nwutils/nw-sample-apps / onMouseDown

Function onMouseDown

mini-code-edit/cm/lib/codemirror.js:353–450  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

351 }
352
353 function onMouseDown(e) {
354 setShift(e_prop(e, "shiftKey"));
355 // Check whether this is a click in a widget
356 for (var n = e_target(e); n != wrapper; n = n.parentNode)
357 if (n.parentNode == code && n != mover) return;
358
359 // See if this is a click in the gutter
360 for (var n = e_target(e); n != wrapper; n = n.parentNode)
361 if (n.parentNode == gutterText) {
362 if (options.onGutterClick)
363 options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom, e);
364 return e_preventDefault(e);
365 }
366
367 var start = posFromMouse(e);
368
369 switch (e_button(e)) {
370 case 3:
371 if (gecko && !mac) onContextMenu(e);
372 return;
373 case 2:
374 if (start) setCursor(start.line, start.ch, true);
375 setTimeout(focusInput, 20);
376 return;
377 }
378 // For button 1, if it was clicked inside the editor
379 // (posFromMouse returning non-null), we have to adjust the
380 // selection.
381 if (!start) {if (e_target(e) == scroller) e_preventDefault(e); return;}
382
383 if (!focused) onFocus();
384
385 var now = +new Date;
386 if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
387 e_preventDefault(e);
388 setTimeout(focusInput, 20);
389 return selectLine(start.line);
390 } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
391 lastDoubleClick = {time: now, pos: start};
392 e_preventDefault(e);
393 return selectWordAt(start);
394 } else { lastClick = {time: now, pos: start}; }
395
396 var last = start, going;
397 if (options.dragDrop && dragAndDrop && !options.readOnly && !posEq(sel.from, sel.to) &&
398 !posLess(start, sel.from) && !posLess(sel.to, start)) {
399 // Let the drag handler handle this.
400 if (webkit) lineSpace.draggable = true;
401 function dragEnd(e2) {
402 if (webkit) lineSpace.draggable = false;
403 draggingText = false;
404 up(); drop();
405 if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
406 e_preventDefault(e2);
407 setCursor(start.line, start.ch, true);
408 focusInput();
409 }
410 }

Callers

nothing calls this directly

Calls 15

setShiftFunction · 0.85
e_propFunction · 0.85
e_targetFunction · 0.85
e_preventDefaultFunction · 0.85
posFromMouseFunction · 0.85
e_buttonFunction · 0.85
onContextMenuFunction · 0.85
setCursorFunction · 0.85
onFocusFunction · 0.85
posEqFunction · 0.85
selectLineFunction · 0.85
selectWordAtFunction · 0.85

Tested by

no test coverage detected