MCPcopy Create free account
hub / github.com/TruthHun/BookStack / leftButtonSelect

Function leftButtonSelect

static/mergely/lib/codemirror.js:3662–3804  ·  view source on GitHub ↗
(cm, e, start, type, addNew)

Source from the content-addressed store, hash-verified

3660
3661 // Normal selection, as opposed to text dragging.
3662 function leftButtonSelect(cm, e, start, type, addNew) {
3663 var display = cm.display, doc = cm.doc;
3664 e_preventDefault(e);
3665
3666 var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
3667 if (addNew && !e.shiftKey) {
3668 ourIndex = doc.sel.contains(start);
3669 if (ourIndex > -1)
3670 ourRange = ranges[ourIndex];
3671 else
3672 ourRange = new Range(start, start);
3673 } else {
3674 ourRange = doc.sel.primary();
3675 ourIndex = doc.sel.primIndex;
3676 }
3677
3678 if (e.altKey) {
3679 type = "rect";
3680 if (!addNew) ourRange = new Range(start, start);
3681 start = posFromMouse(cm, e, true, true);
3682 ourIndex = -1;
3683 } else if (type == "double") {
3684 var word = cm.findWordAt(start);
3685 if (cm.display.shift || doc.extend)
3686 ourRange = extendRange(doc, ourRange, word.anchor, word.head);
3687 else
3688 ourRange = word;
3689 } else if (type == "triple") {
3690 var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
3691 if (cm.display.shift || doc.extend)
3692 ourRange = extendRange(doc, ourRange, line.anchor, line.head);
3693 else
3694 ourRange = line;
3695 } else {
3696 ourRange = extendRange(doc, ourRange, start);
3697 }
3698
3699 if (!addNew) {
3700 ourIndex = 0;
3701 setSelection(doc, new Selection([ourRange], 0), sel_mouse);
3702 startSel = doc.sel;
3703 } else if (ourIndex == -1) {
3704 ourIndex = ranges.length;
3705 setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
3706 {scroll: false, origin: "*mouse"});
3707 } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) {
3708 setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
3709 {scroll: false, origin: "*mouse"});
3710 startSel = doc.sel;
3711 } else {
3712 replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
3713 }
3714
3715 var lastPos = start;
3716 function extendTo(pos) {
3717 if (cmp(lastPos, pos) == 0) return;
3718 lastPos = pos;
3719

Callers 1

leftButtonDownFunction · 0.70

Calls 11

posFromMouseFunction · 0.70
extendRangeFunction · 0.70
clipPosFunction · 0.70
setSelectionFunction · 0.70
normalizeSelectionFunction · 0.70
replaceOneSelectionFunction · 0.70
operationFunction · 0.70
e_buttonFunction · 0.70
doneFunction · 0.70
extendFunction · 0.70
onFunction · 0.50

Tested by

no test coverage detected