MCPcopy Index your code
hub / github.com/witheve/Eve / selectBlock

Function selectBlock

src/codemirror.js:12108–12144  ·  view source on GitHub ↗
(cm, selectionEnd)

Source from the content-addressed store, hash-verified

12106 // Width of the block:
12107 // Distance between selectionEnd.ch and any(first considered here) selection.ch
12108 function selectBlock(cm, selectionEnd) {
12109 var selections = [], ranges = cm.listSelections();
12110 var head = copyCursor(cm.clipPos(selectionEnd));
12111 var isClipped = !cursorEqual(selectionEnd, head);
12112 var curHead = cm.getCursor('head');
12113 var primIndex = getIndex(ranges, curHead);
12114 var wasClipped = cursorEqual(ranges[primIndex].head, ranges[primIndex].anchor);
12115 var max = ranges.length - 1;
12116 var index = max - primIndex > primIndex ? max : 0;
12117 var base = ranges[index].anchor;
12118
12119 var firstLine = Math.min(base.line, head.line);
12120 var lastLine = Math.max(base.line, head.line);
12121 var baseCh = base.ch, headCh = head.ch;
12122
12123 var dir = ranges[index].head.ch - baseCh;
12124 var newDir = headCh - baseCh;
12125 if (dir > 0 && newDir <= 0) {
12126 baseCh++;
12127 if (!isClipped) { headCh--; }
12128 } else if (dir < 0 && newDir >= 0) {
12129 baseCh--;
12130 if (!wasClipped) { headCh++; }
12131 } else if (dir < 0 && newDir == -1) {
12132 baseCh--;
12133 headCh++;
12134 }
12135 for (var line = firstLine; line <= lastLine; line++) {
12136 var range = {anchor: new Pos(line, baseCh), head: new Pos(line, headCh)};
12137 selections.push(range);
12138 }
12139 primIndex = head.line == lastLine ? selections.length - 1 : 0;
12140 cm.setSelections(selections);
12141 selectionEnd.ch = headCh;
12142 base.ch = baseCh;
12143 return base;
12144 }
12145 function selectForInsert(cm, head, height) {
12146 var sel = [];
12147 for (var i = 0; i < height; i++) {

Callers 1

VimFunction · 0.85

Calls 5

copyCursorFunction · 0.85
cursorEqualFunction · 0.85
getIndexFunction · 0.85
listSelectionsMethod · 0.80
getCursorMethod · 0.80

Tested by

no test coverage detected