(cm, e, start, type, addNew)
| 3682 | |
| 3683 | // Normal selection, as opposed to text dragging. |
| 3684 | function leftButtonSelect(cm, e, start, type, addNew) { |
| 3685 | var display = cm.display, doc = cm.doc; |
| 3686 | e_preventDefault(e); |
| 3687 | |
| 3688 | var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges; |
| 3689 | if (addNew && !e.shiftKey) { |
| 3690 | ourIndex = doc.sel.contains(start); |
| 3691 | if (ourIndex > -1) |
| 3692 | ourRange = ranges[ourIndex]; |
| 3693 | else |
| 3694 | ourRange = new Range(start, start); |
| 3695 | } else { |
| 3696 | ourRange = doc.sel.primary(); |
| 3697 | ourIndex = doc.sel.primIndex; |
| 3698 | } |
| 3699 | |
| 3700 | if (chromeOS ? e.shiftKey && e.metaKey : e.altKey) { |
| 3701 | type = "rect"; |
| 3702 | if (!addNew) ourRange = new Range(start, start); |
| 3703 | start = posFromMouse(cm, e, true, true); |
| 3704 | ourIndex = -1; |
| 3705 | } else if (type == "double") { |
| 3706 | var word = cm.findWordAt(start); |
| 3707 | if (cm.display.shift || doc.extend) |
| 3708 | ourRange = extendRange(doc, ourRange, word.anchor, word.head); |
| 3709 | else |
| 3710 | ourRange = word; |
| 3711 | } else if (type == "triple") { |
| 3712 | var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0))); |
| 3713 | if (cm.display.shift || doc.extend) |
| 3714 | ourRange = extendRange(doc, ourRange, line.anchor, line.head); |
| 3715 | else |
| 3716 | ourRange = line; |
| 3717 | } else { |
| 3718 | ourRange = extendRange(doc, ourRange, start); |
| 3719 | } |
| 3720 | |
| 3721 | if (!addNew) { |
| 3722 | ourIndex = 0; |
| 3723 | setSelection(doc, new Selection([ourRange], 0), sel_mouse); |
| 3724 | startSel = doc.sel; |
| 3725 | } else if (ourIndex == -1) { |
| 3726 | ourIndex = ranges.length; |
| 3727 | setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex), |
| 3728 | {scroll: false, origin: "*mouse"}); |
| 3729 | } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) { |
| 3730 | setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), |
| 3731 | {scroll: false, origin: "*mouse"}); |
| 3732 | startSel = doc.sel; |
| 3733 | } else { |
| 3734 | replaceOneSelection(doc, ourIndex, ourRange, sel_mouse); |
| 3735 | } |
| 3736 | |
| 3737 | var lastPos = start; |
| 3738 | function extendTo(pos) { |
| 3739 | if (cmp(lastPos, pos) == 0) return; |
| 3740 | lastPos = pos; |
| 3741 |
no test coverage detected