summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcmacrae <calum0macrae@gmail.com>2018-11-20 17:59:08 +0000
committercmacrae <calum0macrae@gmail.com>2018-11-20 17:59:08 +0000
commite5cc9317dc7019d4f2a211891331e2cc2ff2d9c0 (patch)
tree4c5514b5b3cc066240a920df85db937231799fda
parentedeaabebd3212d0fb1075d9bbedd063eb77446d2 (diff)
keys: Implement yank (C-y)
-rw-r--r--up.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/up.go b/up.go
index 3900df8..89e7fb5 100644
--- a/up.go
+++ b/up.go
@@ -283,9 +283,10 @@ func NewEditor(prompt string) *Editor {
type Editor struct {
// TODO: make editor multiline. Reuse gocui or something for this?
- prompt []rune
- value []rune
- cursor int
+ prompt []rune
+ value []rune
+ killspace []rune
+ cursor int
// lastw is length of value on last Draw; we need it to know how much to erase after backspace
lastw int
}
@@ -341,7 +342,9 @@ func (e *Editor) HandleKey(ev *tcell.EventKey) bool {
case ctrlKey(tcell.KeyCtrlE):
e.cursor = e.lastw
case ctrlKey(tcell.KeyCtrlK):
- e.value = e.value[:e.cursor]
+ e.kill()
+ case ctrlKey(tcell.KeyCtrlY):
+ e.yank()
default:
// Unknown key/combination, not handled
return false
@@ -366,6 +369,20 @@ func (e *Editor) delete(dx int) {
e.cursor = pos
}
+func (e *Editor) kill() {
+ e.killspace = e.value[e.cursor:]
+ e.value = e.value[:e.cursor]
+}
+
+func (e *Editor) yank() {
+ if len(e.killspace) == 0 {
+ return
+ }
+ for _, r := range e.killspace {
+ e.insert(r)
+ }
+}
+
type BufView struct {
// TODO: Wrap bool
Y int // Y of the view in the Buf, for down/up scrolling