MCPcopy
hub / github.com/nwutils/nw-sample-apps / findPosH

Function findPosH

mini-code-edit/cm/lib/codemirror.js:1249–1277  ·  view source on GitHub ↗
(dir, unit)

Source from the content-addressed store, hash-verified

1247 }
1248
1249 function findPosH(dir, unit) {
1250 var end = sel.inverted ? sel.from : sel.to, line = end.line, ch = end.ch;
1251 var lineObj = getLine(line);
1252 function findNextLine() {
1253 for (var l = line + dir, e = dir < 0 ? -1 : doc.size; l != e; l += dir) {
1254 var lo = getLine(l);
1255 if (!lo.hidden) { line = l; lineObj = lo; return true; }
1256 }
1257 }
1258 function moveOnce(boundToLine) {
1259 if (ch == (dir < 0 ? 0 : lineObj.text.length)) {
1260 if (!boundToLine && findNextLine()) ch = dir < 0 ? lineObj.text.length : 0;
1261 else return false;
1262 } else ch += dir;
1263 return true;
1264 }
1265 if (unit == "char") moveOnce();
1266 else if (unit == "column") moveOnce(true);
1267 else if (unit == "word") {
1268 var sawWord = false;
1269 for (;;) {
1270 if (dir < 0) if (!moveOnce()) break;
1271 if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
1272 else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
1273 if (dir > 0) if (!moveOnce()) break;
1274 }
1275 }
1276 return {line: line, ch: ch};
1277 }
1278 function moveH(dir, unit) {
1279 var pos = dir < 0 ? sel.from : sel.to;
1280 if (shiftSelecting || posEq(sel.from, sel.to)) pos = findPosH(dir, unit);

Callers 2

moveHFunction · 0.85
deleteHFunction · 0.85

Calls 3

getLineFunction · 0.85
moveOnceFunction · 0.85
isWordCharFunction · 0.85

Tested by

no test coverage detected