From 3e520c699a306682e5dd7647e355aac1b7db0dc1 Mon Sep 17 00:00:00 2001 From: Aki Kareha Date: Thu, 26 Mar 2026 10:55:31 +0900 Subject: [PATCH] Add x command --- internal/editor/command.go | 18 ++++++++++++++++++ internal/editor/editor.go | 2 ++ 2 files changed, 20 insertions(+) diff --git a/internal/editor/command.go b/internal/editor/command.go index 4bafc5e..019627b 100644 --- a/internal/editor/command.go +++ b/internal/editor/command.go @@ -36,3 +36,21 @@ func (ed *Editor) moveDown(n int) { func (ed *Editor) moveUp(n int) { ed.row = max(ed.row-n, 0) } + +func (ed *Editor) deleteRune(n int) { + if len(ed.lines[ed.row]) < 1 { + return // XXX ring + } + rs := []rune(ed.lines[ed.row]) + if ed.col < 1 { + ed.lines[ed.row] = string(rs[1:]) + } else { + head := string(rs[:ed.col]) + tail := string(rs[ed.col+1:]) + ed.lines[ed.row] = head + tail + } + rc := ed.runeCount() + if ed.row >= rc-1 { + ed.row = rc - 1 + } +} diff --git a/internal/editor/editor.go b/internal/editor/editor.go index d928390..0e8b8b8 100644 --- a/internal/editor/editor.go +++ b/internal/editor/editor.go @@ -265,6 +265,8 @@ func (ed *Editor) Main() { ed.moveDown(1) case 'k': ed.moveUp(1) + case 'x': + ed.deleteRune(1) } case keyUp: ed.moveUp(1)