aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-12-23 20:36:00 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-12-23 20:36:00 +0100
commitf3c4cec24a6bed55eb81ca9e4fb824db2afe951b (patch)
treee460ac508894a1be502ca856bb119b5250d4524a
parent410136a6474b92b45b26a0a92b6e3e7f63d26d9a (diff)
downloadnncmpp-f3c4cec24a6bed55eb81ca9e4fb824db2afe951b.tar.gz
nncmpp-f3c4cec24a6bed55eb81ca9e4fb824db2afe951b.tar.xz
nncmpp-f3c4cec24a6bed55eb81ca9e4fb824db2afe951b.zip
Add and bind an action to center the cursor
"z" stands for VIM's "zz".
-rw-r--r--nncmpp.actions1
-rw-r--r--nncmpp.c19
2 files changed, 18 insertions, 2 deletions
diff --git a/nncmpp.actions b/nncmpp.actions
index 2fde391..06ac727 100644
--- a/nncmpp.actions
+++ b/nncmpp.actions
@@ -42,6 +42,7 @@ INCREMENTAL_SEARCH, Incremental search
SCROLL_UP, Scroll up
SCROLL_DOWN, Scroll down
+CENTER_CURSOR, Center the cursor
MOVE_UP, Move selection up
MOVE_DOWN, Move selection down
diff --git a/nncmpp.c b/nncmpp.c
index 3e4383b..d915d24 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -2213,6 +2213,19 @@ app_ensure_selection_visible (void)
}
static bool
+app_center_cursor (void)
+{
+ struct tab *tab = g.active_tab;
+ if (tab->item_selected < 0 || !tab->item_count)
+ return false;
+
+ int offset = tab->item_selected - tab->item_top;
+ int target = app_visible_items () / 2;
+ app_scroll (offset - target);
+ return true;
+}
+
+static bool
app_move_selection (int diff)
{
struct tab *tab = g.active_tab;
@@ -2509,9 +2522,10 @@ app_process_action (enum action action)
case ACTION_PULSE_MUTE: return pulse_volume_mute (&g.pulse);
#endif // WITH_PULSE
- // XXX: these should rather be parametrized
+ // XXX: these two should rather be parametrized
case ACTION_SCROLL_UP: return app_scroll (-3);
- case ACTION_SCROLL_DOWN: return app_scroll (3);
+ case ACTION_SCROLL_DOWN: return app_scroll (+3);
+ case ACTION_CENTER_CURSOR: return app_center_cursor ();
case ACTION_GOTO_TOP:
if (tab->item_count)
@@ -2737,6 +2751,7 @@ g_normal_defaults[] =
{ "C-f", ACTION_GOTO_PAGE_NEXT },
{ "C-y", ACTION_SCROLL_UP },
{ "C-e", ACTION_SCROLL_DOWN },
+ { "z", ACTION_CENTER_CURSOR },
{ "H", ACTION_GOTO_VIEW_TOP },
{ "M", ACTION_GOTO_VIEW_CENTER },