MCPcopy
hub / github.com/ajaxorg/ace / expandWordUnderCursor

Function expandWordUnderCursor

src/keyboard/vim.js:4562–4625  ·  view source on GitHub ↗
(cm, {inclusive, innerWord, bigWord, noSymbol, multiline}, cursor)

Source from the content-addressed store, hash-verified

4560 }
4561
4562 function expandWordUnderCursor(cm, {inclusive, innerWord, bigWord, noSymbol, multiline}, cursor) {
4563 var cur = cursor || getHead(cm);
4564 var line = cm.getLine(cur.line);
4565 var endLine = line;
4566 var startLineNumber = cur.line
4567 var endLineNumber = startLineNumber;
4568 var idx = cur.ch;
4569
4570 var wordOnNextLine;
4571 // Seek to first word or non-whitespace character, depending on if
4572 // noSymbol is true.
4573 var test = noSymbol ? wordCharTest[0] : bigWordCharTest [0];
4574 if (innerWord && /\s/.test(line.charAt(idx))) {
4575 test = function(ch) { return /\s/.test(ch); };
4576 } else {
4577 while (!test(line.charAt(idx))) {
4578 idx++;
4579 if (idx >= line.length) {
4580 if (!multiline) return null;
4581 idx--;
4582 wordOnNextLine = findWord(cm, cur, true, bigWord, true);
4583 break
4584 }
4585 }
4586
4587 if (bigWord) {
4588 test = bigWordCharTest[0];
4589 } else {
4590 test = wordCharTest[0];
4591 if (!test(line.charAt(idx))) {
4592 test = wordCharTest[1];
4593 }
4594 }
4595 }
4596
4597 var end = idx, start = idx;
4598 while (test(line.charAt(start)) && start >= 0) { start--; }
4599 start++;
4600 if (wordOnNextLine) {
4601 end = wordOnNextLine.to;
4602 endLineNumber = wordOnNextLine.line;
4603 endLine = cm.getLine(endLineNumber);
4604 if (!endLine && end == 0) end++;
4605 } else {
4606 while (test(line.charAt(end)) && end < line.length) { end++; }
4607 }
4608
4609 if (inclusive) {
4610 // If present, include all whitespace after word.
4611 // Otherwise, include all whitespace before word, except indentation.
4612 var wordEnd = end;
4613 var startsWithSpace = cur.ch <= start && /\s/.test(line.charAt(cur.ch));
4614 if (!startsWithSpace) {
4615 while (/\s/.test(endLine.charAt(end)) && end < endLine.length) { end++; }
4616 }
4617 if (wordEnd == end || startsWithSpace) {
4618 var wordStart = start;
4619 while (/\s/.test(line.charAt(start - 1)) && start > 0) { start--; }

Callers 1

vim.jsFile · 0.85

Calls 4

getHeadFunction · 0.85
findWordFunction · 0.85
testFunction · 0.70
getLineMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…