Add x command

This commit is contained in:
2026-03-26 10:55:31 +09:00
parent 157ebafdc6
commit 3e520c699a
2 changed files with 20 additions and 0 deletions

View File

@@ -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
}
}

View File

@@ -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)