=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/mode-tree.c,v retrieving revision 1.10 retrieving revision 1.11 diff -c -r1.10 -r1.11 *** src/usr.bin/tmux/mode-tree.c 2017/08/27 09:08:36 1.10 --- src/usr.bin/tmux/mode-tree.c 2017/09/08 16:28:41 1.11 *************** *** 1,4 **** ! /* $OpenBSD: mode-tree.c,v 1.10 2017/08/27 09:08:36 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: mode-tree.c,v 1.11 2017/09/08 16:28:41 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott *************** *** 128,133 **** --- 128,144 ---- } static void + mode_tree_check_selected(struct mode_tree_data *mtd) + { + /* + * If the current line would now be off screen reset the offset to the + * last visible line. + */ + if (mtd->current > mtd->height - 1) + mtd->offset = mtd->current - mtd->height + 1; + } + + static void mode_tree_clear_lines(struct mode_tree_data *mtd) { free(mtd->line_list); *************** *** 192,198 **** if (i != mtd->line_size) { mtd->current = i; if (mtd->current > mtd->height - 1) ! mtd->offset = 1 + mtd->current - mtd->height; else mtd->offset = 0; } else { --- 203,209 ---- if (i != mtd->line_size) { mtd->current = i; if (mtd->current > mtd->height - 1) ! mtd->offset = mtd->current - mtd->height + 1; else mtd->offset = 0; } else { *************** *** 361,366 **** --- 372,378 ---- mtd->height = screen_size_y(s); } else mtd->height = screen_size_y(s); + mode_tree_check_selected(mtd); } static void *************** *** 792,798 **** case KEYC_END: mtd->current = mtd->line_size - 1; if (mtd->current > mtd->height - 1) ! mtd->offset = mtd->current - mtd->height; else mtd->offset = 0; break; --- 804,810 ---- case KEYC_END: mtd->current = mtd->line_size - 1; if (mtd->current > mtd->height - 1) ! mtd->offset = mtd->current - mtd->height + 1; else mtd->offset = 0; break; *************** *** 870,884 **** case 'v': mtd->preview = !mtd->preview; mode_tree_build(mtd); ! ! /* ! * If the current line would now be off screen now the preview ! * is on, reset the the offset to the last visible line. ! */ ! if (mtd->preview && mtd->current > mtd->height - 1) { ! mtd->offset = mtd->current - mtd->height; ! mtd->current--; ! } break; } return (0); --- 882,889 ---- case 'v': mtd->preview = !mtd->preview; mode_tree_build(mtd); ! if (mtd->preview) ! mode_tree_check_selected(mtd); break; } return (0);