MCPcopy Create free account
hub / github.com/breck7/scroll / findPosH

Function findPosH

external/.scrollLibs.js:11898–11968  ·  view source on GitHub ↗
(doc, pos, dir, unit, visually)

Source from the content-addressed store, hash-verified

11896 // position. The resulting position will have a hitSide=true
11897 // property if it reached the end of the document.
11898 function findPosH(doc, pos, dir, unit, visually) {
11899 var oldPos = pos
11900 var origDir = dir
11901 var lineObj = getLine(doc, pos.line)
11902 function findNextLine() {
11903 var l = pos.line + dir
11904 if (l < doc.first || l >= doc.first + doc.size) {
11905 return false
11906 }
11907 pos = new Pos(l, pos.ch, pos.sticky)
11908 return (lineObj = getLine(doc, l))
11909 }
11910 function moveOnce(boundToLine) {
11911 var next
11912 if (visually) {
11913 next = moveVisually(doc.cm, lineObj, pos, dir)
11914 } else {
11915 next = moveLogically(lineObj, pos, dir)
11916 }
11917 if (next == null) {
11918 if (!boundToLine && findNextLine()) {
11919 pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir)
11920 } else {
11921 return false
11922 }
11923 } else {
11924 pos = next
11925 }
11926 return true
11927 }
11928
11929 if (unit == "char") {
11930 moveOnce()
11931 } else if (unit == "column") {
11932 moveOnce(true)
11933 } else if (unit == "word" || unit == "group") {
11934 var sawType = null,
11935 group = unit == "group"
11936 var helper = doc.cm && doc.cm.getHelper(pos, "wordChars")
11937 for (var first = true; ; first = false) {
11938 if (dir < 0 && !moveOnce(!first)) {
11939 break
11940 }
11941 var cur = lineObj.text.charAt(pos.ch) || "\n"
11942 var type = isAtomChar(cur, helper) ? "w" : group && cur == "\n" ? "n" : !group || /\s/.test(cur) ? null : "p"
11943 if (group && !first && !type) {
11944 type = "s"
11945 }
11946 if (sawType && sawType != type) {
11947 if (dir < 0) {
11948 dir = 1
11949 moveOnce()
11950 pos.sticky = "after"
11951 }
11952 break
11953 }
11954
11955 if (type) {

Callers 1

addEditorMethodsFunction · 0.85

Calls 5

getLineFunction · 0.85
moveOnceFunction · 0.85
isAtomCharFunction · 0.85
skipAtomicFunction · 0.85
equalCursorPosFunction · 0.85

Tested by

no test coverage detected