diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-09-27 08:47:26 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-09-27 08:56:12 +0200 |
commit | 77d5b10ee0d6fc9f000d9ebf523995a7ae7d98bf (patch) | |
tree | c12d61d85f44ed830a81c9d42dbebe67bfa5156e | |
parent | 55afda8a7387ae670ead4cc07a250ac969723aa1 (diff) | |
download | calcurse-77d5b10ee0d6fc9f000d9ebf523995a7ae7d98bf.tar.gz calcurse-77d5b10ee0d6fc9f000d9ebf523995a7ae7d98bf.zip |
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 <kevin.wang2004@hotmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r-- | src/wins.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -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; } |