From 77d5b10ee0d6fc9f000d9ebf523995a7ae7d98bf Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 27 Sep 2016 08:47:26 +0200 Subject: Fix key binding pagination Do not create an empty key bindings page if the number of bindings is a multiple of the number of slots per page. Also, add comments to explain the computation. Reported-by: Kevin Wang Signed-off-by: Lukas Fleischer --- src/wins.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/wins.c b/src/wins.c index 16a88fc..11cfa83 100644 --- a/src/wins.c +++ b/src/wins.c @@ -717,11 +717,24 @@ void wins_erase_status_bar(void) /* Update the status bar page number to display other commands. */ void wins_other_status_page(int panel) { - int max_page = bindings_size / (KEYS_CMDS_PER_LINE * 2 - 1) + 1; - - /* There is no "OtherCmd" on the last page. */ - if (bindings_size % (KEYS_CMDS_PER_LINE * 2 - 1) == 1) - max_page--; + /* + * Determine the number of completely filled pages of key bindings. + * There are two lines of bindings and KEYS_CMDS_PER_LINE bindings per + * line. On each page (other than the last page), one slot is reserved + * for OtherCmd. + */ + const int slots_per_page = KEYS_CMDS_PER_LINE * 2 - 1; + int max_page = bindings_size / slots_per_page; + + /* + * The result of the previous computation might have been rounded down. + * In this case, there are some bindings left. If there is exactly one + * binding left, it can be squashed onto the last page in place of the + * OtherCmd binding. If there are at least two bindings left, we need + * to add another page. + */ + if (bindings_size % slots_per_page > 1) + max_page++; status_page = (status_page % max_page) + 1; } -- cgit v1.2.3-54-g00ecf