(cm, event, pos, behavior)
| 7379 | // Start a text drag. When it ends, see if any dragging actually |
| 7380 | // happen, and treat as a click if it didn't. |
| 7381 | function leftButtonStartDrag(cm, event, pos, behavior) { |
| 7382 | var display = cm.display, moved = false; |
| 7383 | var dragEnd = operation(cm, function (e) { |
| 7384 | if (webkit) { display.scroller.draggable = false; } |
| 7385 | cm.state.draggingText = false; |
| 7386 | if (cm.state.delayingBlurEvent) { |
| 7387 | if (cm.hasFocus()) { cm.state.delayingBlurEvent = false; } |
| 7388 | else { delayBlurEvent(cm); } |
| 7389 | } |
| 7390 | off(display.wrapper.ownerDocument, "mouseup", dragEnd); |
| 7391 | off(display.wrapper.ownerDocument, "mousemove", mouseMove); |
| 7392 | off(display.scroller, "dragstart", dragStart); |
| 7393 | off(display.scroller, "drop", dragEnd); |
| 7394 | if (!moved) { |
| 7395 | e_preventDefault(e); |
| 7396 | if (!behavior.addNew) |
| 7397 | { extendSelection(cm.doc, pos, null, null, behavior.extend); } |
| 7398 | // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081) |
| 7399 | if ((webkit && !safari) || ie && ie_version == 9) |
| 7400 | { setTimeout(function () {display.wrapper.ownerDocument.body.focus({preventScroll: true}); display.input.focus();}, 20); } |
| 7401 | else |
| 7402 | { display.input.focus(); } |
| 7403 | } |
| 7404 | }); |
| 7405 | var mouseMove = function(e2) { |
| 7406 | moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10; |
| 7407 | }; |
| 7408 | var dragStart = function () { return moved = true; }; |
| 7409 | // Let the drag handler handle this. |
| 7410 | if (webkit) { display.scroller.draggable = true; } |
| 7411 | cm.state.draggingText = dragEnd; |
| 7412 | dragEnd.copy = !behavior.moveOnDrag; |
| 7413 | on(display.wrapper.ownerDocument, "mouseup", dragEnd); |
| 7414 | on(display.wrapper.ownerDocument, "mousemove", mouseMove); |
| 7415 | on(display.scroller, "dragstart", dragStart); |
| 7416 | on(display.scroller, "drop", dragEnd); |
| 7417 | |
| 7418 | cm.state.delayingBlurEvent = true; |
| 7419 | setTimeout(function () { return display.input.focus(); }, 20); |
| 7420 | // IE's approach to draggable |
| 7421 | if (display.scroller.dragDrop) { display.scroller.dragDrop(); } |
| 7422 | } |
| 7423 | |
| 7424 | function rangeForUnit(cm, pos, unit) { |
| 7425 | if (unit == "char") { return new Range(pos, pos) } |
no test coverage detected