From 121baddb4cd919d98bf5dfea0ad78ca0bee58a2e Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 9 Jan 2017 21:53:38 +0100 Subject: Move left and right --- buffer.cpp | 26 +++++++++++++++++++++++++- config.cpp | 4 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/buffer.cpp b/buffer.cpp index f077bbb..78f5e16 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -62,10 +62,34 @@ void Buffer::receive(const Command &cmd){ tb.erase(cursor.line,cursor.x); renewLayout(screen[0].line,screen[0].part,lastWidth,lastHeight); } + } else if(cmd[0]=="move_forward"){ + if(cursor.line==tb.numLines()-1&&cursor.x==tb.lineLen(cursor.line)){ + bel(); + } else { + if(cursor.x==tb.lineLen(cursor.line)){ + cursor.x=0; + cursor.line++; + } else { + cursor.x++; + } + renewLayout(screen[0].line,screen[0].part,lastWidth,lastHeight); + } + } else if(cmd[0]=="move_backward"){ + if(cursor.line==0&&cursor.x==0){ + bel(); + } else { + if(cursor.x==0){ + cursor.line--; + cursor.x=tb.lineLen(cursor.line); + } else { + cursor.x--; + } + renewLayout(screen[0].line,screen[0].part,lastWidth,lastHeight); + } } else { THROW("Unknown command"); } - cerr<<"New cursor is (line="<