MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / findPosH

Function findPosH

static/js/codemirror/codemirror.js:2520–2555  ·  view source on GitHub ↗
(doc, pos, dir, unit, visually)

Source from the content-addressed store, hash-verified

2518 }
2519
2520 function findPosH(doc, pos, dir, unit, visually) {
2521 var line = pos.line, ch = pos.ch;
2522 var lineObj = getLine(doc, line);
2523 var possible = true;
2524 function findNextLine() {
2525 var l = line + dir;
2526 if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
2527 line = l;
2528 return lineObj = getLine(doc, l);
2529 }
2530 function moveOnce(boundToLine) {
2531 var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
2532 if (next == null) {
2533 if (!boundToLine && findNextLine()) {
2534 if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
2535 else ch = dir < 0 ? lineObj.text.length : 0;
2536 } else return (possible = false);
2537 } else ch = next;
2538 return true;
2539 }
2540
2541 if (unit == "char") moveOnce();
2542 else if (unit == "column") moveOnce(true);
2543 else if (unit == "word") {
2544 var sawWord = false;
2545 for (;;) {
2546 if (dir < 0) if (!moveOnce()) break;
2547 if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
2548 else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
2549 if (dir > 0) if (!moveOnce()) break;
2550 }
2551 }
2552 var result = skipAtomic(doc, Pos(line, ch), dir, true);
2553 if (!possible) result.hitSide = true;
2554 return result;
2555 }
2556
2557 function findPosV(cm, pos, dir, unit) {
2558 var doc = cm.doc, x = pos.left, y;

Callers 1

codemirror.jsFile · 0.85

Calls 5

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

Tested by

no test coverage detected