MCPcopy Index your code
hub / github.com/csev/py4e / leftButtonSelect

Function leftButtonSelect

tools/pythonauto/static/codemirrorepl/codemirror.js:2581–2713  ·  view source on GitHub ↗
(cm, e, start, type, addNew)

Source from the content-addressed store, hash-verified

2579
2580 // Normal selection, as opposed to text dragging.
2581 function leftButtonSelect(cm, e, start, type, addNew) {
2582 var display = cm.display, doc = cm.doc;
2583 e_preventDefault(e);
2584
2585 var ourRange, ourIndex, startSel = doc.sel;
2586 if (addNew) {
2587 ourIndex = doc.sel.contains(start);
2588 if (ourIndex > -1)
2589 ourRange = doc.sel.ranges[ourIndex];
2590 else
2591 ourRange = new Range(start, start);
2592 } else {
2593 ourRange = doc.sel.primary();
2594 }
2595
2596 if (e.altKey) {
2597 type = "rect";
2598 if (!addNew) ourRange = new Range(start, start);
2599 start = posFromMouse(cm, e, true, true);
2600 ourIndex = -1;
2601 } else if (type == "double") {
2602 var word = findWordAt(doc, start);
2603 if (cm.display.shift || doc.extend)
2604 ourRange = extendRange(doc, ourRange, word.anchor, word.head);
2605 else
2606 ourRange = word;
2607 } else if (type == "triple") {
2608 var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
2609 if (cm.display.shift || doc.extend)
2610 ourRange = extendRange(doc, ourRange, line.anchor, line.head);
2611 else
2612 ourRange = line;
2613 } else {
2614 ourRange = extendRange(doc, ourRange, start);
2615 }
2616
2617 if (!addNew) {
2618 ourIndex = 0;
2619 setSelection(doc, new Selection([ourRange], 0), sel_mouse);
2620 } else if (ourIndex > -1) {
2621 replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
2622 } else {
2623 ourIndex = doc.sel.ranges.length;
2624 setSelection(doc, normalizeSelection(doc.sel.ranges.concat([ourRange]), ourIndex),
2625 {scroll: false, origin: "*mouse"});
2626 }
2627
2628 var lastPos = start;
2629 function extendTo(pos) {
2630 if (cmp(lastPos, pos) == 0) return;
2631 lastPos = pos;
2632
2633 if (type == "rect") {
2634 var ranges = [], tabSize = cm.options.tabSize;
2635 var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
2636 var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
2637 var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
2638 for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));

Callers 1

leftButtonDownFunction · 0.85

Calls 14

extendRangeFunction · 0.85
PosFunction · 0.85
replaceOneSelectionFunction · 0.85
normalizeSelectionFunction · 0.85
onFunction · 0.85
e_preventDefaultFunction · 0.70
posFromMouseFunction · 0.70
findWordAtFunction · 0.70
clipPosFunction · 0.70
setSelectionFunction · 0.70
operationFunction · 0.70
e_buttonFunction · 0.70

Tested by

no test coverage detected