summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 76378f6)
raw | patch | inline | side by side (parent: 76378f6)
author | Max Kellermann <max@duempel.org> | |
Tue, 16 Sep 2008 16:52:55 +0000 (18:52 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Tue, 16 Sep 2008 16:52:55 +0000 (18:52 +0200) |
Apparently, somebody was too lazy to derive the formulas for cursor
movement, and wrote lots of while loops.
movement, and wrote lots of while loops.
src/list_window.c | patch | blob | history |
diff --git a/src/list_window.c b/src/list_window.c
index af8abc9d4c07874b10077448618d05ac63401ae2..967f56a7b53f8d31448d190b1b27f3762977a5ce 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
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
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;
}
}