From 14cac64019b3425eb40eb82471b0995d62b9a7a2 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 10 Jan 2017 10:47:49 +0100 Subject: Auto-scroll on move_forward (and fix fCIS) --- buffer.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'buffer.cpp') diff --git a/buffer.cpp b/buffer.cpp index 97c898f..1ace091 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -71,6 +71,10 @@ void Buffer::handleCommand(const Command &cmd){ } else { cursor.x++; } + if(findCursorInScreen().x==-1){ + screen.erase(screen.begin()); + relayoutScreen(); + } } else if(cmd[0]=="move_backward"){ if(cursor.line==0&&cursor.x==0){ bel(); @@ -123,7 +127,7 @@ void Buffer::handleCommand(const Command &cmd){ void Buffer::receive(const Command &cmd){ handleCommand(cmd); - cerr<<"New cursor is (line="<tb.lineLen(cursor.line)){ + THROW("Invalid cursor position: past end of line"); + } auto lineit=lower_bound(screen.begin(),screen.end(),cursor.line,[this](const ScreenLine &sl,i64 line){ return sl.line &cells=lineit->cells; + + const i64 y=lineit==screen.end()?screen.size()-1:distance(screen.begin(),lineit)-1; + if(screen[y].line!=cursor.line)return {-1,-1}; //cursor is below screen on a new line + const vector &cells=screen[y].cells; auto chrit=lower_bound(cells.begin(),cells.end(),cursor.x,[](const Cell &cell,i64 x){ return cell.linex