From 4b7701110efd769ce8cd13fd1be7dc7e329da5fb Mon Sep 17 00:00:00 2001 From: MeexReay Date: Fri, 21 Mar 2025 21:50:50 +0300 Subject: [PATCH] add insert line mode --- app/kfc/kfc.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/kfc/kfc.js b/app/kfc/kfc.js index 9c582b1..2541af3 100644 --- a/app/kfc/kfc.js +++ b/app/kfc/kfc.js @@ -27,6 +27,12 @@ async function printScreen(screen_length, start_cursor, pos, content, mode, pos, return [screen.length + status_line.length, status_line.length - 1] } +function editLine(content, line, callback) { + let lines = content.split("\n") + lines[line] = callback(lines[line]) + return lines.join("\n") +} + async function main(args) { if (args.length != 2) { writeStdout(`Usage: kfc \n`) @@ -110,7 +116,8 @@ async function main(args) { mode = "insert" } } else if (mode == "insert") { - + content = editLine(content, pos[1], line => line.slice(0, pos[0]) + event.char + line.slice(pos[0])) + pos[0] += 1 } }