(cm, vim)
| 12162 | return -1; |
| 12163 | } |
| 12164 | function getSelectedAreaRange(cm, vim) { |
| 12165 | var lastSelection = vim.lastSelection; |
| 12166 | var getCurrentSelectedAreaRange = function() { |
| 12167 | var selections = cm.listSelections(); |
| 12168 | var start = selections[0]; |
| 12169 | var end = selections[selections.length-1]; |
| 12170 | var selectionStart = cursorIsBefore(start.anchor, start.head) ? start.anchor : start.head; |
| 12171 | var selectionEnd = cursorIsBefore(end.anchor, end.head) ? end.head : end.anchor; |
| 12172 | return [selectionStart, selectionEnd]; |
| 12173 | }; |
| 12174 | var getLastSelectedAreaRange = function() { |
| 12175 | var selectionStart = cm.getCursor(); |
| 12176 | var selectionEnd = cm.getCursor(); |
| 12177 | var block = lastSelection.visualBlock; |
| 12178 | if (block) { |
| 12179 | var width = block.width; |
| 12180 | var height = block.height; |
| 12181 | selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width); |
| 12182 | var selections = []; |
| 12183 | // selectBlock creates a 'proper' rectangular block. |
| 12184 | // We do not want that in all cases, so we manually set selections. |
| 12185 | for (var i = selectionStart.line; i < selectionEnd.line; i++) { |
| 12186 | var anchor = Pos(i, selectionStart.ch); |
| 12187 | var head = Pos(i, selectionEnd.ch); |
| 12188 | var range = {anchor: anchor, head: head}; |
| 12189 | selections.push(range); |
| 12190 | } |
| 12191 | cm.setSelections(selections); |
| 12192 | } else { |
| 12193 | var start = lastSelection.anchorMark.find(); |
| 12194 | var end = lastSelection.headMark.find(); |
| 12195 | var line = end.line - start.line; |
| 12196 | var ch = end.ch - start.ch; |
| 12197 | selectionEnd = {line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch}; |
| 12198 | if (lastSelection.visualLine) { |
| 12199 | selectionStart = Pos(selectionStart.line, 0); |
| 12200 | selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line)); |
| 12201 | } |
| 12202 | cm.setSelection(selectionStart, selectionEnd); |
| 12203 | } |
| 12204 | return [selectionStart, selectionEnd]; |
| 12205 | }; |
| 12206 | if (!vim.visualMode) { |
| 12207 | // In case of replaying the action. |
| 12208 | return getLastSelectedAreaRange(); |
| 12209 | } else { |
| 12210 | return getCurrentSelectedAreaRange(); |
| 12211 | } |
| 12212 | } |
| 12213 | // Updates the previous selection with the current selection's values. This |
| 12214 | // should only be called in visual mode. |
| 12215 | function updateLastSelection(cm, vim) { |
no test coverage detected