Skip to content

Commit

Permalink
Fix <0 error with paging
Browse files Browse the repository at this point in the history
  • Loading branch information
newsch committed May 29, 2019
1 parent 8444011 commit 3760875
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/fe_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,35 @@ int master_handler(State *state, WINDOW *canvas_win, WINDOW *status_win) {
// shift view down/up/left/right
// renaming for ease of use
const int h = getmaxy(canvas_win) - 2; // height of visible canvas
const int w = getmaxx(canvas_win) - 2; // width
const int w = getmaxx(canvas_win) - 2; // width of visible canvas
const int vy = state->view->y;
const int vx = state->view->x;
const int ch = state->view->canvas->num_rows;
const int cw = state->view->canvas->num_cols;
const int ch = state->view->canvas->num_rows; // height of total canvas
const int cw = state->view->canvas->num_cols; // width of total canvas
int new_vy = vy;
int new_vx = vx;
// calc shift based on key
switch (c) {
case KEY_NPAGE: // down
new_vy = min(vy + h, ch - h);
// b/c canvas snaps to the top left corner, we need to be more careful
// when moving down or right. Move to either:
// another window height
// | or the end of the visible canvas
// | | (when the canvas is smaller than the window, this
// v v is less than zero, so get the max of the two)
new_vy = min(vy + h, max(ch - h, 0));
break;
case KEY_PPAGE: // up
new_vy = max(0, vy - h);
break;
case KEY_SRIGHT:
new_vx = min(vx + w, cw - w);
case KEY_SRIGHT: // right
// similar situation to moving down - jump to another window width or
// the end of the canvas, and check for negative values
new_vx = min(vx + w, max(cw - w, 0));
break;
case KEY_SLEFT:
case KEY_SLEFT: // left
new_vx = max(0, vx - w);
break;
}
// shift view
state->view->y = new_vy;
Expand Down

0 comments on commit 3760875

Please sign in to comment.