summaryrefslogtreecommitdiff
path: root/buffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'buffer.cpp')
-rw-r--r--buffer.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/buffer.cpp b/buffer.cpp
index 182c285..b8e0d75 100644
--- a/buffer.cpp
+++ b/buffer.cpp
@@ -189,6 +189,42 @@ void Buffer::handleCommand(const Command &cmd){
} else {
cursor.x=screen[sp.y].cells[sp.x].linex;
}
+ } else if(cmd[0]=="move_pagedown"){
+ Screenpos sp=findCursorInScreen();
+ if(sp.x==-1||screen.size()==0){
+ bel();
+ return;
+ }
+ i64 lastLine=screen.back().line;
+ i64 lastX=screen.back().cells.size()==0 ? screen.back().fromx : screen.back().cells.back().linex+1;
+ i64 newTopLine,newTopPart;
+ if(lastX>=tb.lineLen(lastLine)){
+ if(lastLine==tb.numLines()-1){
+ cursor.line=lastLine;
+ cursor.x=lastX;
+ return;
+ }
+ newTopLine=lastLine+1;
+ newTopPart=0;
+ } else {
+ newTopLine=lastLine;
+ newTopPart=screen.back().part+1;
+ }
+ vector<ScreenLine> screenCopy=screen;
+ renewLayout(newTopLine,newTopPart,lastWidth,lastHeight);
+ if((i64)screen.size()<lastHeight){
+ i64 gap=lastHeight-screen.size();
+ screen.insert(screen.begin(),screenCopy.begin()+(screenCopy.size()-gap),screenCopy.end());
+ cursor.line=screen.back().line;
+ if(screen.back().cells.size()==0)cursor.x=screen.back().fromx;
+ else cursor.x=screen.back().cells.back().linex+1;
+ } else {
+ cursor.line=screen[sp.y].line;
+ if((i64)screen[sp.y].cells.size()<sp.x){
+ if(screen[sp.y].cells.size()==0)cursor.x=screen[sp.y].fromx;
+ else cursor.x=screen[sp.y].cells.back().linex+1;
+ }
+ }
} else if(cmd[0]=="cancel"){
bel(); //nothing to cancel, apparently
} else {
@@ -347,11 +383,6 @@ void Buffer::renewLayout(i64 topLine,i64 topPart,i64 width,i64 height){
if((i64)screen.size()>height){
screen.resize(height);
}
-
- if(findCursorInScreen().x==-1){ //We lost the cursor! Let's find it again
- performInitialLayout(width,height);
- cerr<<"Re-performing initial layout because cursor was lost in renewLayout"<<endl;
- }
}
void Buffer::relayoutScreen(){