diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-09 21:53:38 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-09 21:53:38 +0100 |
commit | 121baddb4cd919d98bf5dfea0ad78ca0bee58a2e (patch) | |
tree | 6bc753aec60a53b9578159e449ec17d9446e57e8 | |
parent | c772fd46fb1902807b5908245c80492078706477 (diff) |
Move left and right
-rw-r--r-- | buffer.cpp | 26 | ||||
-rw-r--r-- | config.cpp | 4 |
2 files changed, 29 insertions, 1 deletions
@@ -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){ @@ -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(){ |