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

Function selectBlock

lib/web/CodeMirror/keymap/vim.js:3054–3089  ·  view source on GitHub ↗
(cm, selectionEnd)

Source from the content-addressed store, hash-verified

3052 // Width of the block:
3053 // Distance between selectionEnd.ch and any(first considered here) selection.ch
3054 function selectBlock(cm, selectionEnd) {
3055 var selections = [], ranges = cm.listSelections();
3056 var head = copyCursor(cm.clipPos(selectionEnd));
3057 var isClipped = !cursorEqual(selectionEnd, head);
3058 var curHead = cm.getCursor('head');
3059 var primIndex = getIndex(ranges, curHead);
3060 var wasClipped = cursorEqual(ranges[primIndex].head, ranges[primIndex].anchor);
3061 var max = ranges.length - 1;
3062 var index = max - primIndex > primIndex ? max : 0;
3063 var base = ranges[index].anchor;
3064
3065 var firstLine = Math.min(base.line, head.line);
3066 var lastLine = Math.max(base.line, head.line);
3067 var baseCh = base.ch, headCh = head.ch;
3068
3069 var dir = ranges[index].head.ch - baseCh;
3070 var newDir = headCh - baseCh;
3071 if (dir > 0 && newDir <= 0) {
3072 baseCh++;
3073 if (!isClipped) { headCh--; }
3074 } else if (dir < 0 && newDir >= 0) {
3075 baseCh--;
3076 if (!wasClipped) { headCh++; }
3077 } else if (dir < 0 && newDir == -1) {
3078 baseCh--;
3079 headCh++;
3080 }
3081 for (var line = firstLine; line <= lastLine; line++) {
3082 var range = {anchor: new Pos(line, baseCh), head: new Pos(line, headCh)};
3083 selections.push(range);
3084 }
3085 cm.setSelections(selections);
3086 selectionEnd.ch = headCh;
3087 base.ch = baseCh;
3088 return base;
3089 }
3090 function selectForInsert(cm, head, height) {
3091 var sel = [];
3092 for (var i = 0; i < height; i++) {

Callers 1

VimFunction · 0.85

Calls 6

cursorEqualFunction · 0.85
getIndexFunction · 0.85
copyCursorFunction · 0.70
minMethod · 0.45
maxMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected