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
@ -5,7 +5,7 @@ package editor
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
const (
|
const (
|
||||||
KiloVersion = "0.0.1"
|
KiloVersion = "0.0.1"
|
||||||
KiloTabStop = 4
|
KiloTabStop = 4
|
||||||
KiloQuitTimes = 3
|
KiloQuitTimes = 3
|
||||||
)
|
)
|
||||||
|
@ -22,13 +22,13 @@ type statusMsg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type editor struct {
|
type editor struct {
|
||||||
screen *terminal.Screen
|
screen *terminal.Screen
|
||||||
cursor *point
|
cursor *point
|
||||||
offset *point
|
offset *point
|
||||||
document *document
|
document *document
|
||||||
status *statusMsg
|
status *statusMsg
|
||||||
quitTimes uint8
|
quitTimes uint8
|
||||||
renderX int
|
renderX int
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *editor {
|
func New() *editor {
|
||||||
@ -100,6 +100,7 @@ func (e *editor) ProcessKeypress() bool {
|
|||||||
case key.Enter:
|
case key.Enter:
|
||||||
|
|
||||||
case key.Backspace, key.Ctrl('h'):
|
case key.Backspace, key.Ctrl('h'):
|
||||||
|
e.delChar()
|
||||||
|
|
||||||
case key.Esc, key.Ctrl('l'):
|
case key.Esc, key.Ctrl('l'):
|
||||||
// Modifier keys that return ANSI escape sequences
|
// Modifier keys that return ANSI escape sequences
|
||||||
@ -116,6 +117,10 @@ func (e *editor) ProcessKeypress() bool {
|
|||||||
keyEnd:
|
keyEnd:
|
||||||
|
|
||||||
e.moveCursor(str)
|
e.moveCursor(str)
|
||||||
|
|
||||||
|
case keyDelete:
|
||||||
|
e.moveCursor(keyRight)
|
||||||
|
e.delChar()
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -209,6 +214,19 @@ func (e *editor) insertChar(ch rune) {
|
|||||||
e.document.dirty = true
|
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
|
// Convert the raw ANSI escape sequences to the type of key input
|
||||||
func parseEscapeSequence() string {
|
func parseEscapeSequence() string {
|
||||||
var runes []rune
|
var runes []rune
|
||||||
|
@ -54,6 +54,25 @@ func (r *row) insertRune(ch rune, at int) {
|
|||||||
r.update()
|
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() {
|
func (r *row) update() {
|
||||||
r.render = r.render[:0]
|
r.render = r.render[:0]
|
||||||
replacement := strings.Repeat(" ", KiloTabStop)
|
replacement := strings.Repeat(" ", KiloTabStop)
|
||||||
|
Loading…
Reference in New Issue
Block a user