(doc, pos, dir, unit, visually)
| 3701 | // position. The resulting position will have a hitSide=true |
| 3702 | // property if it reached the end of the document. |
| 3703 | function findPosH(doc, pos, dir, unit, visually) { |
| 3704 | var line = pos.line, ch = pos.ch, origDir = dir; |
| 3705 | var lineObj = getLine(doc, line); |
| 3706 | var possible = true; |
| 3707 | function findNextLine() { |
| 3708 | var l = line + dir; |
| 3709 | if (l < doc.first || l >= doc.first + doc.size) return (possible = false); |
| 3710 | line = l; |
| 3711 | return lineObj = getLine(doc, l); |
| 3712 | } |
| 3713 | function moveOnce(boundToLine) { |
| 3714 | var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true); |
| 3715 | if (next == null) { |
| 3716 | if (!boundToLine && findNextLine()) { |
| 3717 | if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj); |
| 3718 | else ch = dir < 0 ? lineObj.text.length : 0; |
| 3719 | } else return (possible = false); |
| 3720 | } else ch = next; |
| 3721 | return true; |
| 3722 | } |
| 3723 | |
| 3724 | if (unit == "char") moveOnce(); |
| 3725 | else if (unit == "column") moveOnce(true); |
| 3726 | else if (unit == "word" || unit == "group") { |
| 3727 | var sawType = null, group = unit == "group"; |
| 3728 | for (var first = true;; first = false) { |
| 3729 | if (dir < 0 && !moveOnce(!first)) break; |
| 3730 | var cur = lineObj.text.charAt(ch) || "\n"; |
| 3731 | var type = isWordChar(cur) ? "w" |
| 3732 | : group && cur == "\n" ? "n" |
| 3733 | : !group || /\s/.test(cur) ? null |
| 3734 | : "p"; |
| 3735 | if (group && !first && !type) type = "s"; |
| 3736 | if (sawType && sawType != type) { |
| 3737 | if (dir < 0) {dir = 1; moveOnce();} |
| 3738 | break; |
| 3739 | } |
| 3740 | |
| 3741 | if (type) sawType = type; |
| 3742 | if (dir > 0 && !moveOnce(!first)) break; |
| 3743 | } |
| 3744 | } |
| 3745 | var result = skipAtomic(doc, Pos(line, ch), origDir, true); |
| 3746 | if (!possible) result.hitSide = true; |
| 3747 | return result; |
| 3748 | } |
| 3749 | |
| 3750 | // For relative vertical movement. Dir may be -1 or 1. Unit can be |
| 3751 | // "page" or "line". The resulting position will have a hitSide=true |
no test coverage detected