(cm, cur, forward, bigWord, emptyLineIsWord)
| 4818 | * the word, or null if there are no more words. |
| 4819 | */ |
| 4820 | function findWord(cm, cur, forward, bigWord, emptyLineIsWord) { |
| 4821 | var lineNum = cur.line; |
| 4822 | var pos = cur.ch; |
| 4823 | var line = cm.getLine(lineNum); |
| 4824 | var dir = forward ? 1 : -1; |
| 4825 | var charTests = bigWord ? bigWordCharTest: wordCharTest; |
| 4826 | |
| 4827 | if (emptyLineIsWord && line == '') { |
| 4828 | lineNum += dir; |
| 4829 | line = cm.getLine(lineNum); |
| 4830 | if (!isLine(cm, lineNum)) { |
| 4831 | return null; |
| 4832 | } |
| 4833 | pos = (forward) ? 0 : line.length; |
| 4834 | } |
| 4835 | |
| 4836 | while (true) { |
| 4837 | if (emptyLineIsWord && line == '') { |
| 4838 | return { from: 0, to: 0, line: lineNum }; |
| 4839 | } |
| 4840 | var stop = (dir > 0) ? line.length : -1; |
| 4841 | var wordStart = stop, wordEnd = stop; |
| 4842 | // Find bounds of next word. |
| 4843 | while (pos != stop) { |
| 4844 | var foundWord = false; |
| 4845 | for (var i = 0; i < charTests.length && !foundWord; ++i) { |
| 4846 | if (charTests[i](line.charAt(pos))) { |
| 4847 | wordStart = pos; |
| 4848 | // Advance to end of word. |
| 4849 | while (pos != stop && charTests[i](line.charAt(pos))) { |
| 4850 | pos += dir; |
| 4851 | } |
| 4852 | wordEnd = pos; |
| 4853 | foundWord = wordStart != wordEnd; |
| 4854 | if (wordStart == cur.ch && lineNum == cur.line && |
| 4855 | wordEnd == wordStart + dir) { |
| 4856 | // We started at the end of a word. Find the next one. |
| 4857 | continue; |
| 4858 | } else { |
| 4859 | return { |
| 4860 | from: Math.min(wordStart, wordEnd + 1), |
| 4861 | to: Math.max(wordStart, wordEnd), |
| 4862 | line: lineNum }; |
| 4863 | } |
| 4864 | } |
| 4865 | } |
| 4866 | if (!foundWord) { |
| 4867 | pos += dir; |
| 4868 | } |
| 4869 | } |
| 4870 | // Advance to next/prev line. |
| 4871 | lineNum += dir; |
| 4872 | if (!isLine(cm, lineNum)) { |
| 4873 | return null; |
| 4874 | } |
| 4875 | line = cm.getLine(lineNum); |
| 4876 | pos = (dir > 0) ? 0 : line.length; |
| 4877 | } |
no test coverage detected
searching dependent graphs…