diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/editor.go | 24 | ||||
-rw-r--r-- | ui/ui.go | 8 |
2 files changed, 26 insertions, 6 deletions
diff --git a/ui/editor.go b/ui/editor.go index e78d8cc..2710e06 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -71,19 +71,31 @@ func (e *editor) RemRune() (ok bool) { if !ok { return } + e.remRuneAt(e.cursorIdx - 1) + e.Left() + return +} +func (e *editor) RemRuneForward() (ok bool) { + ok = e.cursorIdx < len(e.text) + if !ok { + return + } + e.remRuneAt(e.cursorIdx) + return +} + +func (e *editor) remRuneAt(idx int) { // TODO avoid looping twice - rw := e.textWidth[e.cursorIdx] - e.textWidth[e.cursorIdx-1] - for i := e.cursorIdx; i < len(e.textWidth); i++ { + rw := e.textWidth[idx+1] - e.textWidth[idx] + for i := idx + 1; i < len(e.textWidth); i++ { e.textWidth[i] -= rw } - copy(e.textWidth[e.cursorIdx:], e.textWidth[e.cursorIdx+1:]) + copy(e.textWidth[idx+1:], e.textWidth[idx+2:]) e.textWidth = e.textWidth[:len(e.textWidth)-1] - copy(e.text[e.cursorIdx-1:], e.text[e.cursorIdx:]) + copy(e.text[idx:], e.text[idx+1:]) e.text = e.text[:len(e.text)-1] - e.Left() - return } func (e *editor) Flush() (content string) { @@ -174,6 +174,14 @@ func (ui *UI) InputBackspace() (ok bool) { return } +func (ui *UI) InputDelete() (ok bool) { + ok = ui.e.RemRuneForward() + if ok { + ui.draw() + } + return +} + func (ui *UI) InputEnter() (content string) { content = ui.e.Flush() ui.draw() |