Basic character deletion
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
This commit is contained in:
parent
42e50dfebb
commit
f4a252a294
@ -100,6 +100,7 @@ func (e *editor) ProcessKeypress() bool {
|
||||
case key.Enter:
|
||||
|
||||
case key.Backspace, key.Ctrl('h'):
|
||||
e.delChar()
|
||||
|
||||
case key.Esc, key.Ctrl('l'):
|
||||
// Modifier keys that return ANSI escape sequences
|
||||
@ -116,6 +117,10 @@ func (e *editor) ProcessKeypress() bool {
|
||||
keyEnd:
|
||||
|
||||
e.moveCursor(str)
|
||||
|
||||
case keyDelete:
|
||||
e.moveCursor(keyRight)
|
||||
e.delChar()
|
||||
}
|
||||
|
||||
default:
|
||||
@ -209,6 +214,19 @@ func (e *editor) insertChar(ch rune) {
|
||||
e.document.dirty = true
|
||||
}
|
||||
|
||||
func (e *editor) delChar() {
|
||||
if e.cursor.y == e.document.rowCount() {
|
||||
return
|
||||
}
|
||||
|
||||
if e.cursor.x > 0 {
|
||||
e.document.rows[e.cursor.y].deleteRune(e.cursor.x - 1)
|
||||
e.cursor.x -= 1
|
||||
}
|
||||
|
||||
e.document.dirty = true
|
||||
}
|
||||
|
||||
// Convert the raw ANSI escape sequences to the type of key input
|
||||
func parseEscapeSequence() string {
|
||||
var runes []rune
|
||||
|
@ -54,6 +54,25 @@ func (r *row) insertRune(ch rune, at int) {
|
||||
r.update()
|
||||
}
|
||||
|
||||
func (r *row) deleteRune(at int) {
|
||||
if at < 0 || at >= r.size() {
|
||||
return
|
||||
}
|
||||
|
||||
var newSlice []rune
|
||||
|
||||
// Split the character array at the insertion point
|
||||
start := r.chars[0:at]
|
||||
end := r.chars[at+1 : r.size()] // Skip the index in question
|
||||
|
||||
// Splice it back together
|
||||
newSlice = append(newSlice, start...)
|
||||
newSlice = append(newSlice, end...)
|
||||
|
||||
r.chars = newSlice
|
||||
r.update()
|
||||
}
|
||||
|
||||
func (r *row) update() {
|
||||
r.render = r.render[:0]
|
||||
replacement := strings.Repeat(" ", KiloTabStop)
|
||||
|
Loading…
Reference in New Issue
Block a user