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

Function findWord

lib/web/CodeMirror/keymap/vim.js:3570–3628  ·  view source on GitHub ↗
(cm, cur, forward, bigWord, emptyLineIsWord)

Source from the content-addressed store, hash-verified

3568 * the word, or null if there are no more words.
3569 */
3570 function findWord(cm, cur, forward, bigWord, emptyLineIsWord) {
3571 var lineNum = cur.line;
3572 var pos = cur.ch;
3573 var line = cm.getLine(lineNum);
3574 var dir = forward ? 1 : -1;
3575 var charTests = bigWord ? bigWordCharTest: wordCharTest;
3576
3577 if (emptyLineIsWord && line == '') {
3578 lineNum += dir;
3579 line = cm.getLine(lineNum);
3580 if (!isLine(cm, lineNum)) {
3581 return null;
3582 }
3583 pos = (forward) ? 0 : line.length;
3584 }
3585
3586 while (true) {
3587 if (emptyLineIsWord && line == '') {
3588 return { from: 0, to: 0, line: lineNum };
3589 }
3590 var stop = (dir > 0) ? line.length : -1;
3591 var wordStart = stop, wordEnd = stop;
3592 // Find bounds of next word.
3593 while (pos != stop) {
3594 var foundWord = false;
3595 for (var i = 0; i < charTests.length && !foundWord; ++i) {
3596 if (charTests[i](line.charAt(pos))) {
3597 wordStart = pos;
3598 // Advance to end of word.
3599 while (pos != stop && charTests[i](line.charAt(pos))) {
3600 pos += dir;
3601 }
3602 wordEnd = pos;
3603 foundWord = wordStart != wordEnd;
3604 if (wordStart == cur.ch && lineNum == cur.line &&
3605 wordEnd == wordStart + dir) {
3606 // We started at the end of a word. Find the next one.
3607 continue;
3608 } else {
3609 return {
3610 from: Math.min(wordStart, wordEnd + 1),
3611 to: Math.max(wordStart, wordEnd),
3612 line: lineNum };
3613 }
3614 }
3615 }
3616 if (!foundWord) {
3617 pos += dir;
3618 }
3619 }
3620 // Advance to next/prev line.
3621 lineNum += dir;
3622 if (!isLine(cm, lineNum)) {
3623 return null;
3624 }
3625 line = cm.getLine(lineNum);
3626 pos = (dir > 0) ? 0 : line.length;
3627 }

Callers 1

moveToWordFunction · 0.85

Calls 4

isLineFunction · 0.70
getLineMethod · 0.65
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected