aboutsummaryrefslogtreecommitdiffstats
path: root/src/list_window.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-16 18:52:55 +0200
committerMax Kellermann <max@duempel.org>2008-09-16 18:52:55 +0200
commitff86aacd52311a9da80a147226d28f46b35f2ef8 (patch)
treef500ccb7b147979b94e3b1cf20cfe53a26e1d54e /src/list_window.c
parent76378f6b0116c7fd438791d3e16ed9e542719545 (diff)
downloadmpd-ff86aacd52311a9da80a147226d28f46b35f2ef8.tar.gz
mpd-ff86aacd52311a9da80a147226d28f46b35f2ef8.tar.xz
mpd-ff86aacd52311a9da80a147226d28f46b35f2ef8.zip
list_window: update variables without looping
Apparently, somebody was too lazy to derive the formulas for cursor movement, and wrote lots of while loops.
Diffstat (limited to '')
-rw-r--r--src/list_window.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/list_window.c b/src/list_window.c
index af8abc9d4..967f56a7b 100644
--- a/src/list_window.c
+++ b/src/list_window.c
@@ -67,14 +67,18 @@ list_window_reset(list_window_t *lw)
void
list_window_check_selected(list_window_t *lw, unsigned length)
{
- while (lw->start > 0 && lw->start + lw->rows > length)
- lw->start--;
+ if (lw->start + lw->rows > length) {
+ if (length > lw->rows)
+ lw->start = length - lw->rows;
+ else
+ lw->start = 0;
+ }
- while (lw->selected < lw->start)
- lw->selected++;
+ if (lw->selected < lw->start)
+ lw->selected = lw->start;
- while (lw->selected > 0 && length > 0 && lw->selected >= length)
- lw->selected--;
+ if (length > 0 && lw->selected >= length)
+ lw->selected = length - 1;
}
void
@@ -151,13 +155,13 @@ list_window_paint(list_window_t *lw,
int show_cursor = !(lw->flags & LW_HIDE_CURSOR);
if (show_cursor) {
- while (lw->selected < lw->start) {
- lw->start--;
+ if (lw->selected < lw->start) {
+ lw->start = lw->selected;
lw->clear=1;
}
- while (lw->selected >= lw->start+lw->rows) {
- lw->start++;
+ if (lw->selected >= lw->start + lw->rows) {
+ lw->start = lw->selected - lw->rows + 1;
lw->clear=1;
}
}