MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / insertAtLine

Function insertAtLine

apps/desktop/src/mcp/vault-ops.ts:1161–1177  ·  view source on GitHub ↗
(
  root: string,
  rel: string,
  lineNumber: number,
  text: string
)

Source from the content-addressed store, hash-verified

1159}
1160
1161export async function insertAtLine(
1162 root: string,
1163 rel: string,
1164 lineNumber: number,
1165 text: string
1166): Promise<NoteMeta> {
1167 const abs = resolveSafe(root, rel)
1168 const body = await fs.readFile(abs, 'utf8')
1169 const lines = body.replace(/\r\n/g, '\n').split('\n')
1170 const clamped = Math.max(0, Math.min(lines.length, Math.floor(lineNumber)))
1171 const insertLines = text.split('\n')
1172 lines.splice(clamped, 0, ...insertLines)
1173 await fs.writeFile(abs, lines.join('\n'), 'utf8')
1174 const folder = folderOf(root, abs)
1175 if (!folder) throw new Error(`Note not in a known folder: ${rel}`)
1176 return await readMeta(root, abs, folder)
1177}
1178
1179/* ---------- Backlinks ------------------------------------------------- */
1180

Callers 1

server.tsFile · 0.85

Calls 3

resolveSafeFunction · 0.70
folderOfFunction · 0.70
readMetaFunction · 0.70

Tested by

no test coverage detected