* @param {CodeMirror} cm CodeMirror object. * @param {Pos} cur The position to start from. * @param {int} repeat Number of words to move past. * @param {boolean} forward True to search forward. False to search * backward. * @param {boolean} wordEnd True to move to end of
(cm, cur, repeat, forward, wordEnd, bigWord)
| 12654 | * @return {Cursor} The position the cursor should move to. |
| 12655 | */ |
| 12656 | function moveToWord(cm, cur, repeat, forward, wordEnd, bigWord) { |
| 12657 | var curStart = copyCursor(cur); |
| 12658 | var words = []; |
| 12659 | if (forward && !wordEnd || !forward && wordEnd) { |
| 12660 | repeat++; |
| 12661 | } |
| 12662 | // For 'e', empty lines are not considered words, go figure. |
| 12663 | var emptyLineIsWord = !(forward && wordEnd); |
| 12664 | for (var i = 0; i < repeat; i++) { |
| 12665 | var word = findWord(cm, cur, forward, bigWord, emptyLineIsWord); |
| 12666 | if (!word) { |
| 12667 | var eodCh = lineLength(cm, cm.lastLine()); |
| 12668 | words.push(forward |
| 12669 | ? {line: cm.lastLine(), from: eodCh, to: eodCh} |
| 12670 | : {line: 0, from: 0, to: 0}); |
| 12671 | break; |
| 12672 | } |
| 12673 | words.push(word); |
| 12674 | cur = Pos(word.line, forward ? (word.to - 1) : word.from); |
| 12675 | } |
| 12676 | var shortCircuit = words.length != repeat; |
| 12677 | var firstWord = words[0]; |
| 12678 | var lastWord = words.pop(); |
| 12679 | if (forward && !wordEnd) { |
| 12680 | // w |
| 12681 | if (!shortCircuit && (firstWord.from != curStart.ch || firstWord.line != curStart.line)) { |
| 12682 | // We did not start in the middle of a word. Discard the extra word at the end. |
| 12683 | lastWord = words.pop(); |
| 12684 | } |
| 12685 | return Pos(lastWord.line, lastWord.from); |
| 12686 | } else if (forward && wordEnd) { |
| 12687 | return Pos(lastWord.line, lastWord.to - 1); |
| 12688 | } else if (!forward && wordEnd) { |
| 12689 | // ge |
| 12690 | if (!shortCircuit && (firstWord.to != curStart.ch || firstWord.line != curStart.line)) { |
| 12691 | // We did not start in the middle of a word. Discard the extra word at the end. |
| 12692 | lastWord = words.pop(); |
| 12693 | } |
| 12694 | return Pos(lastWord.line, lastWord.to); |
| 12695 | } else { |
| 12696 | // b |
| 12697 | return Pos(lastWord.line, lastWord.from); |
| 12698 | } |
| 12699 | } |
| 12700 | |
| 12701 | function moveToCharacter(cm, repeat, forward, character) { |
| 12702 | var cur = cm.getCursor(); |
no test coverage detected