MCPcopy Index your code
hub / github.com/DHTMLX/gantt / findPosH

Function findPosH

samples/common/codehighlight/codemirror.js:8666–8730  ·  view source on GitHub ↗
(doc, pos, dir, unit, visually)

Source from the content-addressed store, hash-verified

8664 // of the current position. The resulting position will have a
8665 // hitSide=true property if it reached the end of the document.
8666 function findPosH(doc, pos, dir, unit, visually) {
8667 var oldPos = pos;
8668 var origDir = dir;
8669 var lineObj = getLine(doc, pos.line);
8670 var lineDir = visually && doc.direction == "rtl" ? -dir : dir;
8671 function findNextLine() {
8672 var l = pos.line + lineDir;
8673 if (l < doc.first || l >= doc.first + doc.size) { return false }
8674 pos = new Pos(l, pos.ch, pos.sticky);
8675 return lineObj = getLine(doc, l)
8676 }
8677 function moveOnce(boundToLine) {
8678 var next;
8679 if (unit == "codepoint") {
8680 var ch = lineObj.text.charCodeAt(pos.ch + (dir > 0 ? 0 : -1));
8681 if (isNaN(ch)) {
8682 next = null;
8683 } else {
8684 var astral = dir > 0 ? ch >= 0xD800 && ch < 0xDC00 : ch >= 0xDC00 && ch < 0xDFFF;
8685 next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (astral ? 2 : 1))), -dir);
8686 }
8687 } else if (visually) {
8688 next = moveVisually(doc.cm, lineObj, pos, dir);
8689 } else {
8690 next = moveLogically(lineObj, pos, dir);
8691 }
8692 if (next == null) {
8693 if (!boundToLine && findNextLine())
8694 { pos = endOfLine(visually, doc.cm, lineObj, pos.line, lineDir); }
8695 else
8696 { return false }
8697 } else {
8698 pos = next;
8699 }
8700 return true
8701 }
8702
8703 if (unit == "char" || unit == "codepoint") {
8704 moveOnce();
8705 } else if (unit == "column") {
8706 moveOnce(true);
8707 } else if (unit == "word" || unit == "group") {
8708 var sawType = null, group = unit == "group";
8709 var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
8710 for (var first = true;; first = false) {
8711 if (dir < 0 && !moveOnce(!first)) { break }
8712 var cur = lineObj.text.charAt(pos.ch) || "\n";
8713 var type = isWordChar(cur, helper) ? "w"
8714 : group && cur == "\n" ? "n"
8715 : !group || /\s/.test(cur) ? null
8716 : "p";
8717 if (group && !first && !type) { type = "s"; }
8718 if (sawType && sawType != type) {
8719 if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";}
8720 break
8721 }
8722
8723 if (type) { sawType = type; }

Callers 1

addEditorMethodsFunction · 0.85

Calls 5

getLineFunction · 0.85
moveOnceFunction · 0.85
isWordCharFunction · 0.85
skipAtomicFunction · 0.85
equalCursorPosFunction · 0.85

Tested by

no test coverage detected