MCPcopy Create free account
hub / github.com/csev/py4e / findPosH

Function findPosH

tools/pythonauto/static/codemirror/codemirror.js:2819–2864  ·  view source on GitHub ↗
(doc, pos, dir, unit, visually)

Source from the content-addressed store, hash-verified

2817 }
2818
2819 function findPosH(doc, pos, dir, unit, visually) {
2820 var line = pos.line, ch = pos.ch, origDir = dir;
2821 var lineObj = getLine(doc, line);
2822 var possible = true;
2823 function findNextLine() {
2824 var l = line + dir;
2825 if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
2826 line = l;
2827 return lineObj = getLine(doc, l);
2828 }
2829 function moveOnce(boundToLine) {
2830 var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
2831 if (next == null) {
2832 if (!boundToLine && findNextLine()) {
2833 if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
2834 else ch = dir < 0 ? lineObj.text.length : 0;
2835 } else return (possible = false);
2836 } else ch = next;
2837 return true;
2838 }
2839
2840 if (unit == "char") moveOnce();
2841 else if (unit == "column") moveOnce(true);
2842 else if (unit == "word" || unit == "group") {
2843 var sawType = null, group = unit == "group";
2844 for (var first = true;; first = false) {
2845 if (dir < 0 && !moveOnce(!first)) break;
2846 var cur = lineObj.text.charAt(ch) || "\n";
2847 var type = isWordChar(cur) ? "w"
2848 : group && cur == "\n" ? "n"
2849 : !group || /\s/.test(cur) ? null
2850 : "p";
2851 if (group && !first && !type) type = "s";
2852 if (sawType && sawType != type) {
2853 if (dir < 0) {dir = 1; moveOnce();}
2854 break;
2855 }
2856
2857 if (type) sawType = type;
2858 if (dir > 0 && !moveOnce(!first)) break;
2859 }
2860 }
2861 var result = skipAtomic(doc, Pos(line, ch), origDir, true);
2862 if (!possible) result.hitSide = true;
2863 return result;
2864 }
2865
2866 function findPosV(cm, pos, dir, unit) {
2867 var doc = cm.doc, x = pos.left, y;

Callers 1

codemirror.jsFile · 0.70

Calls 5

PosFunction · 0.85
getLineFunction · 0.70
moveOnceFunction · 0.70
isWordCharFunction · 0.70
skipAtomicFunction · 0.70

Tested by

no test coverage detected