summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 00a64b4)
raw | patch | inline | side by side (parent: 00a64b4)
author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Sat, 17 Sep 2011 20:11:04 +0000 (22:11 +0200) | ||
committer | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Sat, 17 Sep 2011 20:11:04 +0000 (22:11 +0200) |
This moves the list_window_check_origin code into a new, more generic
function, which is exported.
function, which is exported.
src/list_window.c | patch | blob | history | |
src/list_window.h | patch | blob | history |
diff --git a/src/list_window.c b/src/list_window.c
index 8e0b968149e88450d8b5e53370d6a682d7ee8029..ecd786b91d1f3b38b0f56e50e788c98a2feefb83 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
static void
list_window_check_origin(struct list_window *lw)
{
- int start = lw->start;
-
- if ((unsigned) options.scroll_offset * 2 >= lw->rows)
- // Center if the offset is more than half the screen
- start = lw->selected - lw->rows / 2;
- else {
- if (lw->selected < lw->start + options.scroll_offset)
- start = lw->selected - options.scroll_offset;
-
- if (lw->selected >= lw->start + lw->rows - options.scroll_offset)
- start = lw->selected - lw->rows + 1 + options.scroll_offset;
- }
-
- if (start + lw->rows > lw->length)
- start = lw->length - lw->rows;
-
- if (start < 0 || lw->length == 0)
- start = 0;
-
- lw->start = start;
+ list_window_scroll_to(lw, lw->selected);
}
void
}
}
+void
+list_window_scroll_to(struct list_window *lw, unsigned n)
+{
+ int start = lw->start;
+
+ if ((unsigned) options.scroll_offset * 2 >= lw->rows)
+ // Center if the offset is more than half the screen
+ start = n - lw->rows / 2;
+ else {
+ if (n < lw->start + options.scroll_offset)
+ start = n - options.scroll_offset;
+
+ if (n >= lw->start + lw->rows - options.scroll_offset)
+ start = n - lw->rows + 1 + options.scroll_offset;
+ }
+
+ if (start + lw->rows > lw->length)
+ start = lw->length - lw->rows;
+
+ if (start < 0 || lw->length == 0)
+ start = 0;
+
+ lw->start = start;
+}
+
void
list_window_set_cursor(struct list_window *lw, unsigned i)
{
diff --git a/src/list_window.h b/src/list_window.h
index 83beeacaa47f492c162abf4998a2ab7b42349929..8f67c858523602f59f99b4c886853913fb3849a1 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
void
list_window_center(struct list_window *lw, unsigned n);
+/**
+ * Scrolls the view to item n, as if the cursor would have been moved
+ * to the position.
+ */
+void
+list_window_scroll_to(struct list_window *lw, unsigned n);
+
/**
* Sets the position of the cursor. Disables range selection.
*/