1
0
Fork 0

Basic character deletion
timw4mail/gilo/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2021-04-02 10:48:51 -04:00
parent 42e50dfebb
commit f4a252a294
3 changed files with 45 additions and 8 deletions

View File

@ -5,7 +5,7 @@ package editor
// ----------------------------------------------------------------------------
const (
KiloVersion = "0.0.1"
KiloTabStop = 4
KiloVersion = "0.0.1"
KiloTabStop = 4
KiloQuitTimes = 3
)

View File

@ -22,13 +22,13 @@ type statusMsg struct {
}
type editor struct {
screen *terminal.Screen
cursor *point
offset *point
document *document
status *statusMsg
screen *terminal.Screen
cursor *point
offset *point
document *document
status *statusMsg
quitTimes uint8
renderX int
renderX int
}
func New() *editor {
@ -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

View File

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