summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-01-09 21:53:38 +0100
committertomsmeding <tom.smeding@gmail.com>2017-01-09 21:53:38 +0100
commit121baddb4cd919d98bf5dfea0ad78ca0bee58a2e (patch)
tree6bc753aec60a53b9578159e449ec17d9446e57e8
parentc772fd46fb1902807b5908245c80492078706477 (diff)
Move left and right
-rw-r--r--buffer.cpp26
-rw-r--r--config.cpp4
2 files changed, 29 insertions, 1 deletions
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="<<cursor.line<<", x="<<cursor.x<<")"<<endl;
+ //cerr<<"New cursor is (line="<<cursor.line<<", x="<<cursor.x<<")"<<endl;
}
static string showChar(char c){
diff --git a/config.cpp b/config.cpp
index 4d59f55..76cf3a2 100644
--- a/config.cpp
+++ b/config.cpp
@@ -12,6 +12,10 @@ Keybindings global_keybindings={
{KEY_DELETE,{"delete_forward"}},
{'\n',{"insert_newline"}},
{'\t',{"insert_char","\t"}},
+ {KEY_RIGHT,{"move_forward"}},
+ {KEY_LEFT,{"move_backward"}},
+ {KEY_DOWN,{"move_downward"}},
+ {KEY_UP,{"move_upward"}},
};
class Init{public: Init(){