MCPcopy Create free account
hub / github.com/TruthHun/BookStack / findPosH

Function findPosH

static/mergely/lib/codemirror.js:4816–4863  ·  view source on GitHub ↗
(doc, pos, dir, unit, visually)

Source from the content-addressed store, hash-verified

4814 // position. The resulting position will have a hitSide=true
4815 // property if it reached the end of the document.
4816 function findPosH(doc, pos, dir, unit, visually) {
4817 var line = pos.line, ch = pos.ch, origDir = dir;
4818 var lineObj = getLine(doc, line);
4819 function findNextLine() {
4820 var l = line + dir;
4821 if (l < doc.first || l >= doc.first + doc.size) return false
4822 line = l;
4823 return lineObj = getLine(doc, l);
4824 }
4825 function moveOnce(boundToLine) {
4826 var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
4827 if (next == null) {
4828 if (!boundToLine && findNextLine()) {
4829 if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
4830 else ch = dir < 0 ? lineObj.text.length : 0;
4831 } else return false
4832 } else ch = next;
4833 return true;
4834 }
4835
4836 if (unit == "char") {
4837 moveOnce()
4838 } else if (unit == "column") {
4839 moveOnce(true)
4840 } else if (unit == "word" || unit == "group") {
4841 var sawType = null, group = unit == "group";
4842 var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
4843 for (var first = true;; first = false) {
4844 if (dir < 0 && !moveOnce(!first)) break;
4845 var cur = lineObj.text.charAt(ch) || "\n";
4846 var type = isWordChar(cur, helper) ? "w"
4847 : group && cur == "\n" ? "n"
4848 : !group || /\s/.test(cur) ? null
4849 : "p";
4850 if (group && !first && !type) type = "s";
4851 if (sawType && sawType != type) {
4852 if (dir < 0) {dir = 1; moveOnce();}
4853 break;
4854 }
4855
4856 if (type) sawType = type;
4857 if (dir > 0 && !moveOnce(!first)) break;
4858 }
4859 }
4860 var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true);
4861 if (!cmp(pos, result)) result.hitSide = true;
4862 return result;
4863 }
4864
4865 // For relative vertical movement. Dir may be -1 or 1. Unit can be
4866 // "page" or "line". The resulting position will have a hitSide=true

Callers 1

codemirror.jsFile · 0.70

Calls 5

getLineFunction · 0.70
moveOnceFunction · 0.70
isWordCharFunction · 0.70
skipAtomicFunction · 0.70
cmpFunction · 0.50

Tested by

no test coverage detected