MCPcopy
hub / github.com/hokein/electron-sample-apps / clipPos

Function clipPos

mini-code-editor/cm/lib/codemirror.js:1240–1247  ·  view source on GitHub ↗
(pos)

Source from the content-addressed store, hash-verified

1238
1239 function clipLine(n) {return Math.max(0, Math.min(n, doc.size-1));}
1240 function clipPos(pos) {
1241 if (pos.line < 0) return {line: 0, ch: 0};
1242 if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc.size-1).text.length};
1243 var ch = pos.ch, linelen = getLine(pos.line).text.length;
1244 if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
1245 else if (ch < 0) return {line: pos.line, ch: 0};
1246 else return pos;
1247 }
1248
1249 function findPosH(dir, unit) {
1250 var end = sel.inverted ? sel.from : sel.to, line = end.line, ch = end.ch;

Callers 10

CodeMirrorFunction · 0.85
loadFileFunction · 0.85
unredoHelperFunction · 0.85
replaceRangeFunction · 0.85
setSelectionUserFunction · 0.85
setCursorFunction · 0.85
selectLineFunction · 0.85
markTextFunction · 0.85
setBookmarkFunction · 0.85
findMarksAtFunction · 0.85

Calls 1

getLineFunction · 0.85

Tested by

no test coverage detected