MCPcopy
hub / github.com/witheve/Eve / findWord

Function findWord

src/codemirror.js:12584–12642  ·  view source on GitHub ↗

* Returns the boundaries of the next word. If the cursor in the middle of * the word, then returns the boundaries of the current word, starting at * the cursor. If the cursor is at the start/end of a word, and we are going * forward/backward, respectively, find the boundaries of the n

(cm, cur, forward, bigWord, emptyLineIsWord)

Source from the content-addressed store, hash-verified

12582 * the word, or null if there are no more words.
12583 */
12584 function findWord(cm, cur, forward, bigWord, emptyLineIsWord) {
12585 var lineNum = cur.line;
12586 var pos = cur.ch;
12587 var line = cm.getLine(lineNum);
12588 var dir = forward ? 1 : -1;
12589 var charTests = bigWord ? bigWordCharTest: wordCharTest;
12590
12591 if (emptyLineIsWord && line == '') {
12592 lineNum += dir;
12593 line = cm.getLine(lineNum);
12594 if (!isLine(cm, lineNum)) {
12595 return null;
12596 }
12597 pos = (forward) ? 0 : line.length;
12598 }
12599
12600 while (true) {
12601 if (emptyLineIsWord && line == '') {
12602 return { from: 0, to: 0, line: lineNum };
12603 }
12604 var stop = (dir > 0) ? line.length : -1;
12605 var wordStart = stop, wordEnd = stop;
12606 // Find bounds of next word.
12607 while (pos != stop) {
12608 var foundWord = false;
12609 for (var i = 0; i < charTests.length && !foundWord; ++i) {
12610 if (charTests[i](line.charAt(pos))) {
12611 wordStart = pos;
12612 // Advance to end of word.
12613 while (pos != stop && charTests[i](line.charAt(pos))) {
12614 pos += dir;
12615 }
12616 wordEnd = pos;
12617 foundWord = wordStart != wordEnd;
12618 if (wordStart == cur.ch && lineNum == cur.line &&
12619 wordEnd == wordStart + dir) {
12620 // We started at the end of a word. Find the next one.
12621 continue;
12622 } else {
12623 return {
12624 from: Math.min(wordStart, wordEnd + 1),
12625 to: Math.max(wordStart, wordEnd),
12626 line: lineNum };
12627 }
12628 }
12629 }
12630 if (!foundWord) {
12631 pos += dir;
12632 }
12633 }
12634 // Advance to next/prev line.
12635 lineNum += dir;
12636 if (!isLine(cm, lineNum)) {
12637 return null;
12638 }
12639 line = cm.getLine(lineNum);
12640 pos = (dir > 0) ? 0 : line.length;
12641 }

Callers 1

moveToWordFunction · 0.85

Calls 2

isLineFunction · 0.85
getLineMethod · 0.80

Tested by

no test coverage detected