Skip to content

Commit

Permalink
Do not reset yscroll and selection on redraw
Browse files Browse the repository at this point in the history
While here, unify handling of when the selection goes off screen.
  • Loading branch information
Jenz Guenther authored and mptre committed Sep 18, 2017
1 parent 1585928 commit 58c5b46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ selected_choice(void)
xscroll = cursor_position - tty_columns + 1;
else
xscroll = 0;
if (selection - yscroll >= choices_lines)
yscroll = selection - choices_lines + 1;
print_line(&query[xscroll], query_length - xscroll, 0, -1, -1);
choices_count = print_choices(yscroll, selection);
if (choices_count - yscroll < choices.length
Expand Down Expand Up @@ -409,7 +411,6 @@ selected_choice(void)
break;
case CTRL_L:
tty_size();
selection = yscroll = 0;
break;
case CTRL_W:
if (cursor_position == 0)
Expand Down Expand Up @@ -464,13 +465,10 @@ selected_choice(void)
continue;
break;
case PAGE_DOWN:
if (selection + choices_lines < choices_count) {
if (selection + choices_lines < choices_count)
yscroll = selection += choices_lines;
} else {
else
selection = choices_count - 1;
if (selection - yscroll >= choices_lines)
yscroll = choices_count - choices_lines;
}
break;
case PAGE_UP:
if (selection > choices_lines)
Expand All @@ -479,11 +477,8 @@ selected_choice(void)
yscroll = selection = 0;
break;
case END:
if (choices_count > 0) {
if (choices_count > 0)
selection = choices_count - 1;
if (selection - yscroll >= choices_lines)
yscroll = choices_count - choices_lines;
}
break;
case HOME:
yscroll = selection = 0;
Expand Down
4 changes: 2 additions & 2 deletions tests/57.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: CTRL-L clears the selection
description: CTRL-L does not clear the selection
keys: \016 \014 \n # DOWN CTRL_L ENTER
stdin:
a
b
stdout:
a
b

0 comments on commit 58c5b46

Please sign in to comment.