diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-10 21:03:00 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-10 21:03:00 +0100 |
commit | 6d6f45c1e266ffb3206498301a7a6a1b1b22ec3c (patch) | |
tree | 325f00b81348e61e3f0dbddefcba5d424b76c96e | |
parent | 8f3e73313ea0937935d95af7a5d265eaf6009580 (diff) |
Moving up, and bugfixes
- moving up!
- insertion auto-scrolls *correctly*
- moving down can also land *after* the line
-rw-r--r-- | buffer.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
@@ -36,18 +36,20 @@ void Buffer::handleCommand(const Command &cmd){ assert(c!='\n'); tb.insert(cursor.line,cursor.x,cmd[1][0]); cursor.x++; + relayoutScreen(); if(findCursorInScreen().x==-1){ screen.erase(screen.begin()); + relayoutScreen(); } - relayoutScreen(); } else if(cmd[0]=="insert_newline"){ tb.insert(cursor.line,cursor.x,'\n'); cursor.x=0; cursor.line++; + relayoutScreen(); if(findCursorInScreen().x==-1){ screen.erase(screen.begin()); + relayoutScreen(); } - relayoutScreen(); } else if(cmd[0]=="delete_backward"){ if(cursor.x==0&&cursor.line==0){ bel(); @@ -128,7 +130,39 @@ void Buffer::handleCommand(const Command &cmd){ } cursor.line=screen[sp.y].line; if(sp.x>=(i64)screen[sp.y].cells.size()){ - cursor.x=tb.lineLen(cursor.line); + if(screen[sp.y].cells.size()==0)cursor.x=0; + else { + cursor.x=screen[sp.y].cells.back().linex; + //Now if we would've landed *after* the end of the line, go there. + if(cursor.x==tb.lineLen(cursor.line)-1)cursor.x++; + } + } else { + cursor.x=screen[sp.y].cells[sp.x].linex; + } + } else if(cmd[0]=="move_upward"){ + Screenpos sp=findCursorInScreen(); + if(sp.x==-1){ + bel(); + return; + } + if(sp.y==0){ + if(screen[sp.y].line==0&&screen[sp.y].part==0){ + if(cursor.x==0)bel(); + else cursor.x=0; + return; + } + scrollUp(); + } else { + sp.y--; + } + cursor.line=screen[sp.y].line; + if(sp.x>=(i64)screen[sp.y].cells.size()){ + if(screen[sp.y].cells.size()==0)cursor.x=0; + else { + cursor.x=screen[sp.y].cells.back().linex; + //Now if we would've landed *after* the end of the line, go there. + if(cursor.x==tb.lineLen(cursor.line)-1)cursor.x++; + } } else { cursor.x=screen[sp.y].cells[sp.x].linex; } @@ -150,7 +184,7 @@ static string showChar(char c){ } vector<Buffer::ScreenLine> Buffer::layoutLine(const string &line,i64 linenum,i64 width){ - assert(width>=4); + assert(width>=5); //5 == (maximum char repr width) + 1, where the 1 is an extra column on the right if(line.size()==0){ return {{linenum,0,0,{}}}; } |