From a4b51c3e816e31360683aeff7b27e8790ebe32b4 Mon Sep 17 00:00:00 2001 From: Mike Smithson Date: Mon, 18 Apr 2016 13:41:29 +0300 Subject: [PATCH] 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 --- doc/man/mc.1.in | 6 ++++++ src/filemanager/boxes.c | 2 ++ src/filemanager/panel.c | 15 +++++++++++++++ src/setup.c | 2 ++ src/setup.h | 1 + 5 files changed, 26 insertions(+) diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index 2928a0823..b3c40fce2 100644 --- a/doc/man/mc.1.in +++ b/doc/man/mc.1.in @@ -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. diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 22cc8ed42..05d9ea2cf 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -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, diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index cc96ddca9..69f1df952 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -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); } diff --git a/src/setup.c b/src/setup.c index 57c9a36fb..951edb802 100644 --- a/src/setup.c +++ b/src/setup.c @@ -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 }, diff --git a/src/setup.h b/src/setup.h index 47ad560d2..58a8865e0 100644 --- a/src/setup.h +++ b/src/setup.h @@ -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 */ -- 2.11.4.GIT