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

Function makeCmSelection

src/codemirror.js:12267–12315  ·  view source on GitHub ↗
(cm, sel, mode, exclusive)

Source from the content-addressed store, hash-verified

12265 updateFakeCursor(cm);
12266 }
12267 function makeCmSelection(cm, sel, mode, exclusive) {
12268 var head = copyCursor(sel.head);
12269 var anchor = copyCursor(sel.anchor);
12270 if (mode == 'char') {
12271 var headOffset = !exclusive && !cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
12272 var anchorOffset = cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
12273 head = offsetCursor(sel.head, 0, headOffset);
12274 anchor = offsetCursor(sel.anchor, 0, anchorOffset);
12275 return {
12276 ranges: [{anchor: anchor, head: head}],
12277 primary: 0
12278 };
12279 } else if (mode == 'line') {
12280 if (!cursorIsBefore(sel.head, sel.anchor)) {
12281 anchor.ch = 0;
12282
12283 var lastLine = cm.lastLine();
12284 if (head.line > lastLine) {
12285 head.line = lastLine;
12286 }
12287 head.ch = lineLength(cm, head.line);
12288 } else {
12289 head.ch = 0;
12290 anchor.ch = lineLength(cm, anchor.line);
12291 }
12292 return {
12293 ranges: [{anchor: anchor, head: head}],
12294 primary: 0
12295 };
12296 } else if (mode == 'block') {
12297 var top = Math.min(anchor.line, head.line),
12298 left = Math.min(anchor.ch, head.ch),
12299 bottom = Math.max(anchor.line, head.line),
12300 right = Math.max(anchor.ch, head.ch) + 1;
12301 var height = bottom - top + 1;
12302 var primary = head.line == top ? 0 : height - 1;
12303 var ranges = [];
12304 for (var i = 0; i < height; i++) {
12305 ranges.push({
12306 anchor: Pos(top + i, left),
12307 head: Pos(top + i, right)
12308 });
12309 }
12310 return {
12311 ranges: ranges,
12312 primary: primary
12313 };
12314 }
12315 }
12316 function getHead(cm) {
12317 var cur = cm.getCursor('head');
12318 if (cm.getSelection().length == 1) {

Callers 2

VimFunction · 0.85
updateCmSelectionFunction · 0.85

Calls 5

copyCursorFunction · 0.85
cursorIsBeforeFunction · 0.85
offsetCursorFunction · 0.85
lineLengthFunction · 0.85
lastLineMethod · 0.80

Tested by

no test coverage detected