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

Function getSelectedAreaRange

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

Source from the content-addressed store, hash-verified

3107 return -1;
3108 }
3109 function getSelectedAreaRange(cm, vim) {
3110 var lastSelection = vim.lastSelection;
3111 var getCurrentSelectedAreaRange = function() {
3112 var selections = cm.listSelections();
3113 var start = selections[0];
3114 var end = selections[selections.length-1];
3115 var selectionStart = cursorIsBefore(start.anchor, start.head) ? start.anchor : start.head;
3116 var selectionEnd = cursorIsBefore(end.anchor, end.head) ? end.head : end.anchor;
3117 return [selectionStart, selectionEnd];
3118 };
3119 var getLastSelectedAreaRange = function() {
3120 var selectionStart = cm.getCursor();
3121 var selectionEnd = cm.getCursor();
3122 var block = lastSelection.visualBlock;
3123 if (block) {
3124 var width = block.width;
3125 var height = block.height;
3126 selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width);
3127 var selections = [];
3128 // selectBlock creates a 'proper' rectangular block.
3129 // We do not want that in all cases, so we manually set selections.
3130 for (var i = selectionStart.line; i < selectionEnd.line; i++) {
3131 var anchor = Pos(i, selectionStart.ch);
3132 var head = Pos(i, selectionEnd.ch);
3133 var range = {anchor: anchor, head: head};
3134 selections.push(range);
3135 }
3136 cm.setSelections(selections);
3137 } else {
3138 var start = lastSelection.anchorMark.find();
3139 var end = lastSelection.headMark.find();
3140 var line = end.line - start.line;
3141 var ch = end.ch - start.ch;
3142 selectionEnd = {line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch};
3143 if (lastSelection.visualLine) {
3144 selectionStart = Pos(selectionStart.line, 0);
3145 selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line));
3146 }
3147 cm.setSelection(selectionStart, selectionEnd);
3148 }
3149 return [selectionStart, selectionEnd];
3150 };
3151 if (!vim.visualMode) {
3152 // In case of replaying the action.
3153 return getLastSelectedAreaRange();
3154 } else {
3155 return getCurrentSelectedAreaRange();
3156 }
3157 }
3158 // Updates the previous selection with the current selection's values. This
3159 // should only be called in visual mode.
3160 function updateLastSelection(cm, vim) {

Callers 1

VimFunction · 0.85

Calls 2

getLastSelectedAreaRangeFunction · 0.85

Tested by

no test coverage detected