Implemented insert and delete key behaviors.
h3rald h3rald@h3rald.com
Thu, 08 Sep 2016 21:30:27 +0200
1 files changed,
15 insertions(+),
1 deletions(-)
jump to
M
core/line.nim
→
core/line.nim
@@ -106,6 +106,15 @@ putchar i.ord
ln.text = ln.fromFirst & ln.text[ln.position+1..ln.last] stdout.cursorBackward(rest.len) +proc deleteNext*(ln: var Line) = + if not ln.empty: + if not ln.full: + let rest = ln.toLast[1..^1] & " " + for c in rest: + putchar c.ord + stdout.cursorBackward(rest.len) + ln.text = ln.fromFirst & ln.toLast[1..^1] + proc printChar*(ln: var Line, c: int) = if ln.full: putchar(c.cint)@@ -149,7 +158,12 @@
KEYMAP["backspace"] = proc(ln: var Line) = ln.deletePrevious() KEYMAP["delete"] = proc(ln: var Line) = - discard #TODO + ln.deleteNext() +KEYMAP["insert"] = proc(ln: var Line) = + if ln.mode == mdInsert: + ln.mode = mdReplace + else: + ln.mode = mdInsert KEYMAP["down"] = proc(ln: var Line) = discard #TODO KEYMAP["up"] = proc(ln: var Line) =