diff --git a/kilo.c b/kilo.c index 1f4fb23..b641060 100644 --- a/kilo.c +++ b/kilo.c @@ -310,6 +310,7 @@ void abFree(struct abuf *ab) { /*** output ***/ void editorScroll() { + // TODO: I _think_ this conversion should live in editorMoveCursor? E.rx = 0; // Last line (emtpy) is always at 0. if (E.cy < E.numrows) @@ -466,6 +467,16 @@ void editorProcessKeypress() { case PAGE_UP: case PAGE_DOWN: { + // Position either at the top or bottom of the page. + if (c == PAGE_UP) { + E.cy = E.rowoff; + } else { + E.cy = E.rowoff + E.screenrows - 1; + if (E.cy > E.numrows) + E.cy = E.numrows; + } + + // Then simulate an entire screen's worth of movement. int times = E.screenrows; while (times--) { editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN);