regedit: restore list cursor when window is resized
authorChris Davis <cd.rattan@gmail.com>
Wed, 11 Jun 2014 17:40:38 +0000 (10:40 -0700)
committerMichael Adam <obnox@samba.org>
Wed, 1 Oct 2014 12:32:08 +0000 (14:32 +0200)
Signed-off-by: Chris Davis <cd.rattan@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/utils/regedit_list.c

index 2da70bfcb20aeb8d1c68a8264332d3c02b0a6786..417dea8abc05a4859da7896d665283bc8f089516 100644 (file)
@@ -406,6 +406,23 @@ WERROR multilist_set_data(struct multilist *list, const void *data)
        return WERR_OK;
 }
 
+static void fix_start_row(struct multilist *list)
+{
+       int height;
+
+       /* adjust start_row so that the cursor appears on the screen */
+
+       height = list->window_height;
+       if (list->cb->get_column_header) {
+               height--;
+       }
+       if (list->cursor_row < list->start_row) {
+               list->start_row = list->cursor_row;
+       } else if (list->cursor_row >= list->start_row + height) {
+               list->start_row = list->cursor_row - height + 1;
+       }
+}
+
 WERROR multilist_set_window(struct multilist *list, WINDOW *window)
 {
        int maxy, maxx;
@@ -421,10 +438,17 @@ WERROR multilist_set_window(struct multilist *list, WINDOW *window)
        list->window = window;
        list->window_width = maxx;
        list->window_height = maxy;
+       list->start_row = 0;
        if (rerender) {
-               return multilist_set_data(list, list->data);
+               const void *row = multilist_get_current_row(list);
+               WERROR rv = multilist_set_data(list, list->data);
+               if (W_ERROR_IS_OK(rv) && row) {
+                       multilist_set_current_row(list, row);
+               }
+               return rv;
        } else {
                put_header(list);
+               fix_start_row(list);
        }
 
        return WERR_OK;
@@ -449,23 +473,6 @@ void multilist_refresh(struct multilist *list)
                false);
 }
 
-static void fix_start_row(struct multilist *list)
-{
-       int height;
-
-       /* adjust start_row so that the cursor appears on the screen */
-
-       height = list->window_height;
-       if (list->cb->get_column_header) {
-               height--;
-       }
-       if (list->cursor_row < list->start_row) {
-               list->start_row = list->cursor_row;
-       } else if (list->cursor_row >= list->start_row + height) {
-               list->start_row = list->cursor_row - height + 1;
-       }
-}
-
 void multilist_driver(struct multilist *list, int c)
 {
        const void *tmp;