MCPcopy Create free account
hub / github.com/sql-js/sql.js / leftButtonSelect

Function leftButtonSelect

GUI/codemirror/lib/codemirror.js:2611–2744  ·  view source on GitHub ↗
(cm, e, start, type, addNew)

Source from the content-addressed store, hash-verified

2609
2610 // Normal selection, as opposed to text dragging.
2611 function leftButtonSelect(cm, e, start, type, addNew) {
2612 var display = cm.display, doc = cm.doc;
2613 e_preventDefault(e);
2614
2615 var ourRange, ourIndex, startSel = doc.sel;
2616 if (addNew && !e.shiftKey) {
2617 ourIndex = doc.sel.contains(start);
2618 if (ourIndex > -1)
2619 ourRange = doc.sel.ranges[ourIndex];
2620 else
2621 ourRange = new Range(start, start);
2622 } else {
2623 ourRange = doc.sel.primary();
2624 }
2625
2626 if (e.altKey) {
2627 type = "rect";
2628 if (!addNew) ourRange = new Range(start, start);
2629 start = posFromMouse(cm, e, true, true);
2630 ourIndex = -1;
2631 } else if (type == "double") {
2632 var word = findWordAt(doc, start);
2633 if (cm.display.shift || doc.extend)
2634 ourRange = extendRange(doc, ourRange, word.anchor, word.head);
2635 else
2636 ourRange = word;
2637 } else if (type == "triple") {
2638 var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
2639 if (cm.display.shift || doc.extend)
2640 ourRange = extendRange(doc, ourRange, line.anchor, line.head);
2641 else
2642 ourRange = line;
2643 } else {
2644 ourRange = extendRange(doc, ourRange, start);
2645 }
2646
2647 if (!addNew) {
2648 ourIndex = 0;
2649 setSelection(doc, new Selection([ourRange], 0), sel_mouse);
2650 startSel = doc.sel;
2651 } else if (ourIndex > -1) {
2652 replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
2653 } else {
2654 ourIndex = doc.sel.ranges.length;
2655 setSelection(doc, normalizeSelection(doc.sel.ranges.concat([ourRange]), ourIndex),
2656 {scroll: false, origin: "*mouse"});
2657 }
2658
2659 var lastPos = start;
2660 function extendTo(pos) {
2661 if (cmp(lastPos, pos) == 0) return;
2662 lastPos = pos;
2663
2664 if (type == "rect") {
2665 var ranges = [], tabSize = cm.options.tabSize;
2666 var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
2667 var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
2668 var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);

Callers 1

leftButtonDownFunction · 0.85

Calls 12

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…