MCPcopy
hub / github.com/witheve/Eve / findPosH

Function findPosH

src/codemirror.js:4839–4886  ·  view source on GitHub ↗
(doc, pos, dir, unit, visually)

Source from the content-addressed store, hash-verified

4837 // position. The resulting position will have a hitSide=true
4838 // property if it reached the end of the document.
4839 function findPosH(doc, pos, dir, unit, visually) {
4840 var line = pos.line, ch = pos.ch, origDir = dir;
4841 var lineObj = getLine(doc, line);
4842 function findNextLine() {
4843 var l = line + dir;
4844 if (l < doc.first || l >= doc.first + doc.size) return false
4845 line = l;
4846 return lineObj = getLine(doc, l);
4847 }
4848 function moveOnce(boundToLine) {
4849 var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
4850 if (next == null) {
4851 if (!boundToLine && findNextLine()) {
4852 if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
4853 else ch = dir < 0 ? lineObj.text.length : 0;
4854 } else return false
4855 } else ch = next;
4856 return true;
4857 }
4858
4859 if (unit == "char") {
4860 moveOnce()
4861 } else if (unit == "column") {
4862 moveOnce(true)
4863 } else if (unit == "word" || unit == "group") {
4864 var sawType = null, group = unit == "group";
4865 var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
4866 for (var first = true;; first = false) {
4867 if (dir < 0 && !moveOnce(!first)) break;
4868 var cur = lineObj.text.charAt(ch) || "\n";
4869 var type = isWordChar(cur, helper) ? "w"
4870 : group && cur == "\n" ? "n"
4871 : !group || /\s/.test(cur) ? null
4872 : "p";
4873 if (group && !first && !type) type = "s";
4874 if (sawType && sawType != type) {
4875 if (dir < 0) {dir = 1; moveOnce();}
4876 break;
4877 }
4878
4879 if (type) sawType = type;
4880 if (dir > 0 && !moveOnce(!first)) break;
4881 }
4882 }
4883 var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true);
4884 if (!cmp(pos, result)) result.hitSide = true;
4885 return result;
4886 }
4887
4888 // For relative vertical movement. Dir may be -1 or 1. Unit can be
4889 // "page" or "line". The resulting position will have a hitSide=true

Callers 1

codemirror.jsFile · 0.85

Calls 5

getLineFunction · 0.85
moveOnceFunction · 0.85
isWordCharFunction · 0.85
skipAtomicFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected