From 5b91fe424ee7358367f998af8c1903362f9e2abd Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 9 Jan 2017 13:52:11 +0100 Subject: Bugfixing --- buffer.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'buffer.cpp') diff --git a/buffer.cpp b/buffer.cpp index e32492b..2123de1 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "buffer.h" @@ -46,12 +47,11 @@ static string showChar(char c){ "0123456789abcdef"[(unsigned char)c%16]}; } -/*static i64 charWidth(char c){ - return showChar(c).size(); -}*/ - vector Buffer::layoutLine(const string &line,i64 linenum,i64 width){ assert(width>=4); + if(line.size()==0){ + return {{linenum,0,0,{}}}; + } vector layout; vector cur; i64 x=0; @@ -67,7 +67,7 @@ vector Buffer::layoutLine(const string &line,i64 linenum,i64 fromx=i; x=0; } - Cell cell={'\0',repr.size()!=1}; + Cell cell={'\0',repr.size()!=1,i}; for(char rc : repr){ cell.c=rc; cur.push_back(cell); @@ -95,7 +95,7 @@ void Buffer::performInitialLayout(i64 width,i64 height){ //Layout the line the cursor is on. screen=layoutLine(tb[cursor.line],cursor.line,width); i64 cursorScreenY=0; - while(cursorScreenY+1<(i64)screen.size()&&screen[cursorScreenY+1].fromx>cursor.x){ + while(cursorScreenY+1<(i64)screen.size()&&screen[cursorScreenY+1].fromx<=cursor.x){ cursorScreenY++; } @@ -125,9 +125,10 @@ void Buffer::performInitialLayout(i64 width,i64 height){ while(bottomLine layout=layoutLine(tb[bottomLine],bottomLine,width); screen.insert(screen.end(),layout.begin(),layout.end()); + // cerr<<"Added bottomLine="<height){ //Oops, we overran a bit. Prune the end so that we fill the screen exactly. screen.resize(height); } else if((i64)screen.size() layout=layoutLine(tb[bottomLine],bottomLine,width); - screen.insert(screen.begin(),layout.begin(),layout.end()); + screen.insert(screen.end(),layout.begin(),layout.end()); bottomLine++; } @@ -198,8 +199,14 @@ void Buffer::show(i64 atx,i64 aty,i64 width,i64 height){ lastWidth=newWidth; lastHeight=height; } + + setstyle(&textStyle); + fillrect(atx,aty,width,height,' '); + pushcursor(); i64 y; + i64 curScreenX=-1,curScreenY=-1; + // cerr<<"Buffer::show: screen.size()="<