MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / makeCmSelection

Function makeCmSelection

lib/web/CodeMirror/keymap/vim.js:3212–3260  ·  view source on GitHub ↗
(cm, sel, mode, exclusive)

Source from the content-addressed store, hash-verified

3210 updateFakeCursor(cm);
3211 }
3212 function makeCmSelection(cm, sel, mode, exclusive) {
3213 var head = copyCursor(sel.head);
3214 var anchor = copyCursor(sel.anchor);
3215 if (mode == 'char') {
3216 var headOffset = !exclusive && !cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
3217 var anchorOffset = cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
3218 head = offsetCursor(sel.head, 0, headOffset);
3219 anchor = offsetCursor(sel.anchor, 0, anchorOffset);
3220 return {
3221 ranges: [{anchor: anchor, head: head}],
3222 primary: 0
3223 };
3224 } else if (mode == 'line') {
3225 if (!cursorIsBefore(sel.head, sel.anchor)) {
3226 anchor.ch = 0;
3227
3228 var lastLine = cm.lastLine();
3229 if (head.line > lastLine) {
3230 head.line = lastLine;
3231 }
3232 head.ch = lineLength(cm, head.line);
3233 } else {
3234 head.ch = 0;
3235 anchor.ch = lineLength(cm, anchor.line);
3236 }
3237 return {
3238 ranges: [{anchor: anchor, head: head}],
3239 primary: 0
3240 };
3241 } else if (mode == 'block') {
3242 var top = Math.min(anchor.line, head.line),
3243 left = Math.min(anchor.ch, head.ch),
3244 bottom = Math.max(anchor.line, head.line),
3245 right = Math.max(anchor.ch, head.ch) + 1;
3246 var height = bottom - top + 1;
3247 var primary = head.line == top ? 0 : height - 1;
3248 var ranges = [];
3249 for (var i = 0; i < height; i++) {
3250 ranges.push({
3251 anchor: Pos(top + i, left),
3252 head: Pos(top + i, right)
3253 });
3254 }
3255 return {
3256 ranges: ranges,
3257 primary: primary
3258 };
3259 }
3260 }
3261 function getHead(cm) {
3262 var cur = cm.getCursor('head');
3263 if (cm.getSelection().length == 1) {

Callers 2

VimFunction · 0.85
updateCmSelectionFunction · 0.85

Calls 8

cursorIsBeforeFunction · 0.85
copyCursorFunction · 0.70
offsetCursorFunction · 0.70
lineLengthFunction · 0.70
PosFunction · 0.50
minMethod · 0.45
maxMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected