Ticket #3130: implement center scrolling of panel.

Behavior: cause the panel to begin scrolling when the cursor
reaches the middle of the panel, so that the cursor tends to stay in
the middle of the panel on long listings. Only when you reach the
beginning or the end of the listing will the cursor move to the first or
last file.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Mike Smithson 2016-04-18 13:41:29 +03:00 committed by Andrew Borodin
parent 82fc95fb77
commit a4b51c3e81
5 changed files with 26 additions and 0 deletions

View File

@ -2092,6 +2092,12 @@ If set (the default), panel will scroll by half the display when the
cursor reaches the end or the beginning of the panel, otherwise it
will just scroll a file at a time.
.PP
.I Center scrolling.
If set, panel will scroll when the cursor reaches the middle of the
panel, only hitting the top or bottom of the panel when actually on
the first or last file. This behavior applies when scrolling one file
at a time, and does not apply to the page up/down keys.
.PP
.I Mouse page scrolling.
Controls whenever scrolling with the mouse wheel is done by pages or
line by line on the panels.

View File

@ -630,12 +630,14 @@ panel_options_box (void)
NULL),
QUICK_SEPARATOR (FALSE),
QUICK_SEPARATOR (FALSE),
QUICK_SEPARATOR (FALSE),
QUICK_STOP_GROUPBOX,
QUICK_NEXT_COLUMN,
QUICK_START_GROUPBOX (N_("Navigation")),
QUICK_CHECKBOX (N_("L&ynx-like motion"), &panels_options.navigate_with_arrows,
NULL),
QUICK_CHECKBOX (N_("Pa&ge scrolling"), &panels_options.scroll_pages, NULL),
QUICK_CHECKBOX (N_("Center &scrolling"), &panels_options.scroll_center, NULL),
QUICK_CHECKBOX (N_("&Mouse page scrolling"), &panels_options.mouse_move_pages,
NULL),
QUICK_STOP_GROUPBOX,

View File

@ -2102,6 +2102,13 @@ move_down (WPanel * panel)
panel->top_file = panel->dir.len - items;
paint_dir (panel);
}
else if (panels_options.scroll_center && (panel->selected - panel->top_file) > (items / 2))
{
/* Scroll window when cursor is halfway down */
panel->top_file++;
if (panel->top_file > panel->dir.len - items)
panel->top_file = panel->dir.len - items;
}
select_item (panel);
}
@ -2124,6 +2131,14 @@ move_up (WPanel * panel)
panel->top_file = 0;
paint_dir (panel);
}
else if (panels_options.scroll_center
&& (panel->selected - panel->top_file) < (panel_items (panel) / 2))
{
/* Scroll window when cursor is halfway up */
panel->top_file--;
if (panel->top_file < 0)
panel->top_file = 0;
}
select_item (panel);
}

View File

@ -139,6 +139,7 @@ panels_options_t panels_options = {
.auto_save_setup = FALSE,
.navigate_with_arrows = FALSE,
.scroll_pages = TRUE,
.scroll_center = FALSE,
.mouse_move_pages = TRUE,
.filetype_mode = TRUE,
.permission_mode = FALSE,
@ -401,6 +402,7 @@ static const struct
{ "auto_save_setup_panels", &panels_options.auto_save_setup },
{ "navigate_with_arrows", &panels_options.navigate_with_arrows },
{ "panel_scroll_pages", &panels_options.scroll_pages },
{ "panel_scroll_center", &panels_options.scroll_center },
{ "mouse_move_pages", &panels_options.mouse_move_pages },
{ "filetype_mode", &panels_options.filetype_mode },
{ "permission_mode", &panels_options.permission_mode },

View File

@ -48,6 +48,7 @@ typedef struct
gboolean navigate_with_arrows; /* If TRUE: l&r arrows are used to chdir if the input line is empty */
gboolean scroll_pages; /* If TRUE, panel is scrolled by half the display when the cursor reaches
the end or the beginning of the panel */
gboolean scroll_center; /* If TRUE, scroll when the cursor hits the middle of the panel */
gboolean mouse_move_pages; /* Scroll page/item using mouse wheel */
gboolean filetype_mode; /* If TRUE then add per file type hilighting */
gboolean permission_mode; /* If TRUE, we use permission hilighting */