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

Function leftButtonSelect

static/editor.md/lib/codemirror/lib/codemirror.js:3536–3674  ·  view source on GitHub ↗
(cm, e, start, type, addNew)

Source from the content-addressed store, hash-verified

3534
3535 // Normal selection, as opposed to text dragging.
3536 function leftButtonSelect(cm, e, start, type, addNew) {
3537 var display = cm.display, doc = cm.doc;
3538 e_preventDefault(e);
3539
3540 var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
3541 if (addNew && !e.shiftKey) {
3542 ourIndex = doc.sel.contains(start);
3543 if (ourIndex > -1)
3544 ourRange = ranges[ourIndex];
3545 else
3546 ourRange = new Range(start, start);
3547 } else {
3548 ourRange = doc.sel.primary();
3549 }
3550
3551 if (e.altKey) {
3552 type = "rect";
3553 if (!addNew) ourRange = new Range(start, start);
3554 start = posFromMouse(cm, e, true, true);
3555 ourIndex = -1;
3556 } else if (type == "double") {
3557 var word = cm.findWordAt(start);
3558 if (cm.display.shift || doc.extend)
3559 ourRange = extendRange(doc, ourRange, word.anchor, word.head);
3560 else
3561 ourRange = word;
3562 } else if (type == "triple") {
3563 var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
3564 if (cm.display.shift || doc.extend)
3565 ourRange = extendRange(doc, ourRange, line.anchor, line.head);
3566 else
3567 ourRange = line;
3568 } else {
3569 ourRange = extendRange(doc, ourRange, start);
3570 }
3571
3572 if (!addNew) {
3573 ourIndex = 0;
3574 setSelection(doc, new Selection([ourRange], 0), sel_mouse);
3575 startSel = doc.sel;
3576 } else if (ourIndex == -1) {
3577 ourIndex = ranges.length;
3578 setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
3579 {scroll: false, origin: "*mouse"});
3580 } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single") {
3581 setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0));
3582 startSel = doc.sel;
3583 } else {
3584 replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
3585 }
3586
3587 var lastPos = start;
3588 function extendTo(pos) {
3589 if (cmp(lastPos, pos) == 0) return;
3590 lastPos = pos;
3591
3592 if (type == "rect") {
3593 var ranges = [], tabSize = cm.options.tabSize;

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