MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / positionToOffset

Function positionToOffset

src/lib/editorFile.js:43–53  ·  view source on GitHub ↗

* Convert Ace position {row, column} to CodeMirror offset

(pos, doc)

Source from the content-addressed store, hash-verified

41 * Convert Ace position {row, column} to CodeMirror offset
42 */
43 function positionToOffset(pos, doc) {
44 if (!pos || !doc) return 0;
45 try {
46 const lineNum = Math.max(1, Math.min((pos.row ?? 0) + 1, doc.lines));
47 const line = doc.line(lineNum);
48 const col = Math.max(0, Math.min(pos.column ?? 0, line.length));
49 return line.from + col;
50 } catch (_) {
51 return 0;
52 }
53 }
54
55 /**
56 * Convert CodeMirror offset to Ace position {row, column}

Callers 1

getFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected