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

Function clipToLine

lib/web/CodeMirror/keymap/vim.js:3293–3319  ·  view source on GitHub ↗
(cm, curStart, curEnd)

Source from the content-addressed store, hash-verified

3291 // 'dw' should word, but not the newline, while 'w' should advance the
3292 // caret to the first character of the next line.
3293 function clipToLine(cm, curStart, curEnd) {
3294 var selection = cm.getRange(curStart, curEnd);
3295 // Only clip if the selection ends with trailing newline + whitespace
3296 if (/\n\s*$/.test(selection)) {
3297 var lines = selection.split('\n');
3298 // We know this is all whitespace.
3299 lines.pop();
3300
3301 // Cases:
3302 // 1. Last word is an empty line - do not clip the trailing '\n'
3303 // 2. Last word is not an empty line - clip the trailing '\n'
3304 var line;
3305 // Find the line containing the last word, and clip all whitespace up
3306 // to it.
3307 for (var line = lines.pop(); lines.length > 0 && line && isWhiteSpaceString(line); line = lines.pop()) {
3308 curEnd.line--;
3309 curEnd.ch = 0;
3310 }
3311 // If the last word is not an empty line, clip an additional newline
3312 if (line) {
3313 curEnd.line--;
3314 curEnd.ch = lineLength(cm, curEnd.line);
3315 } else {
3316 curEnd.ch = 0;
3317 }
3318 }
3319 }
3320
3321 // Expand the selection to line ends.
3322 function expandSelectionToLine(_cm, curStart, curEnd) {

Callers 1

VimFunction · 0.85

Calls 6

isWhiteSpaceStringFunction · 0.85
lineLengthFunction · 0.70
getRangeMethod · 0.45
testMethod · 0.45
splitMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected