diff options
| -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,{}}};  	} | 
