remove manual cursor move calls

This commit is contained in:
Felix Angell 2018-06-09 10:27:09 +01:00
parent fb6332f2d0
commit 02dc3753ac

View File

@ -561,12 +561,7 @@ func (b *Buffer) deleteNext() {
// FIXME clean this up! // FIXME clean this up!
func (b *Buffer) deletePrev() { func (b *Buffer) deletePrev() {
if b.curs.x > 0 { if b.curs.x > 0 {
offs := -1 if b.cfg.Editor.Hungry_Backspace && b.curs.x >= int(b.cfg.Editor.Tab_Size) {
if !b.cfg.Editor.Tabs_Are_Spaces {
if b.table.Index(b.curs.y, b.curs.x) == '\t' {
offs = int(-b.cfg.Editor.Tab_Size)
}
} else if b.cfg.Editor.Hungry_Backspace && b.curs.x >= int(b.cfg.Editor.Tab_Size) {
// cut out the last {TAB_SIZE} amount of characters // cut out the last {TAB_SIZE} amount of characters
// and check em // and check em
tabSize := int(b.cfg.Editor.Tab_Size) tabSize := int(b.cfg.Editor.Tab_Size)
@ -581,7 +576,10 @@ func (b *Buffer) deletePrev() {
for i := 0; i < int(b.cfg.Editor.Tab_Size); i++ { for i := 0; i < int(b.cfg.Editor.Tab_Size); i++ {
b.table.Delete(b.curs.y, b.curs.x) b.table.Delete(b.curs.y, b.curs.x)
b.curs.move(-1, 0)
// FIXME this was -1, maybe we dont
// want to handle tabs?
b.moveLeft()
} }
return return
} }
@ -594,20 +592,22 @@ func (b *Buffer) deletePrev() {
b.autoComplete.lastRunes = b.autoComplete.lastRunes[:len(b.autoComplete.lastRunes)-1] b.autoComplete.lastRunes = b.autoComplete.lastRunes[:len(b.autoComplete.lastRunes)-1]
} }
b.curs.moveRender(-1, 0, offs, 0) b.moveLeft()
} else if b.curs.x == 0 && b.curs.y > 0 { } else if b.curs.x == 0 && b.curs.y > 0 {
// FIXME
// TODO this should set the previous word // TODO this should set the previous word
// in the auto complete to the word before the cursor after // in the auto complete to the word before the cursor after
// wrapping back the line? // wrapping back the line?
// start of line, wrap to previous // start of line, wrap to previous
prevLineLen := b.table.Lines[b.curs.y-1].Len()
val := b.table.Lines[b.curs.y].String() val := b.table.Lines[b.curs.y].String()
b.table.Insert(val, b.curs.y-1, b.table.Lines[b.curs.y-1].Len()) b.table.Insert(val, b.curs.y-1, b.table.Lines[b.curs.y-1].Len())
b.table.Lines = append(b.table.Lines[:b.curs.y], b.table.Lines[b.curs.y+1:]...) b.table.Lines = append(b.table.Lines[:b.curs.y], b.table.Lines[b.curs.y+1:]...)
b.curs.move(prevLineLen, -1)
b.moveUp()
b.moveToEndOfLine()
} }
} }
@ -1015,25 +1015,28 @@ func (b *Buffer) processActionKey(key int) bool {
if b.cfg.Editor.Tabs_Are_Spaces { if b.cfg.Editor.Tabs_Are_Spaces {
// make an empty rune array of TAB_SIZE, cast to string // make an empty rune array of TAB_SIZE, cast to string
// and insert it. // and insert it.
b.table.Insert(b.makeTab(), b.curs.y, b.curs.x) tab := b.makeTab()
b.curs.move(int(b.cfg.Editor.Tab_Size), 0) b.table.Insert(tab, b.curs.y, b.curs.x)
for i := 0; i < len(tab); i++ {
b.moveRight()
}
} else { } else {
b.table.Insert(string('\t'), b.curs.y, b.curs.x) b.table.Insert(string('\t'), b.curs.y, b.curs.x)
// the actual position is + 1, but we make it b.moveRight()
// move by TAB_SIZE characters on the view.
b.curs.moveRender(1, 0, int(b.cfg.Editor.Tab_Size), 0)
} }
case sdl.K_END: case sdl.K_END:
currLine := b.table.Lines[b.curs.y] currLine := b.table.Lines[b.curs.y]
if b.curs.x < currLine.Len() { if b.curs.x < currLine.Len() {
distToMove := currLine.Len() - b.curs.x distToMove := currLine.Len() - b.curs.x
b.curs.move(distToMove, 0) for i := 0; i < distToMove; i++ {
b.moveRight()
}
} }
case sdl.K_HOME: case sdl.K_HOME:
if b.curs.x > 0 { if b.curs.x > 0 {
b.curs.move(-b.curs.x, 0) b.moveToStartOfLine()
} }
// TODO remove since this is handled in the keymap! // TODO remove since this is handled in the keymap!