* @param {CodeMirror} cm CodeMirror object. * @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 word. False to move to * beginning of word
(cm, repeat, forward, wordEnd, bigWord)
| 1659 | * @return {Cursor} The position the cursor should move to. |
| 1660 | */ |
| 1661 | function moveToWord(cm, repeat, forward, wordEnd, bigWord) { |
| 1662 | var cur = cm.getCursor(); |
| 1663 | for (var i = 0; i < repeat; i++) { |
| 1664 | var startCh = cur.ch, startLine = cur.line, word; |
| 1665 | var movedToNextWord = false; |
| 1666 | while (!movedToNextWord) { |
| 1667 | // Search and advance. |
| 1668 | word = findWord(cm, cur, forward, bigWord); |
| 1669 | movedToNextWord = true; |
| 1670 | if (word) { |
| 1671 | // Move to the word we just found. If by moving to the word we end |
| 1672 | // up in the same spot, then move an extra character and search |
| 1673 | // again. |
| 1674 | cur.line = word.line; |
| 1675 | if (forward && wordEnd) { |
| 1676 | // 'e' |
| 1677 | cur.ch = word.to - 1; |
| 1678 | } else if (forward && !wordEnd) { |
| 1679 | // 'w' |
| 1680 | if (inRangeInclusive(cur.ch, word.from, word.to) && |
| 1681 | word.line == startLine) { |
| 1682 | // Still on the same word. Go to the next one. |
| 1683 | movedToNextWord = false; |
| 1684 | cur.ch = word.to - 1; |
| 1685 | } else { |
| 1686 | cur.ch = word.from; |
| 1687 | } |
| 1688 | } else if (!forward && wordEnd) { |
| 1689 | // 'ge' |
| 1690 | if (inRangeInclusive(cur.ch, word.from, word.to) && |
| 1691 | word.line == startLine) { |
| 1692 | // still on the same word. Go to the next one. |
| 1693 | movedToNextWord = false; |
| 1694 | cur.ch = word.from; |
| 1695 | } else { |
| 1696 | cur.ch = word.to; |
| 1697 | } |
| 1698 | } else if (!forward && !wordEnd) { |
| 1699 | // 'b' |
| 1700 | cur.ch = word.from; |
| 1701 | } |
| 1702 | } else { |
| 1703 | // No more words to be found. Move to the end. |
| 1704 | if (forward) { |
| 1705 | return { line: cur.line, ch: lineLength(cm, cur.line) }; |
| 1706 | } else { |
| 1707 | return { line: cur.line, ch: 0 }; |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | return cur; |
| 1713 | } |
| 1714 | |
| 1715 | function moveToCharacter(cm, repeat, forward, character) { |
| 1716 | var cur = cm.getCursor(); |
no test coverage detected