2 Commits

Author SHA1 Message Date
f3c4cec24a Add and bind an action to center the cursor
"z" stands for VIM's "zz".
2021-12-23 20:36:00 +01:00
410136a647 Fix up coding style inconsistency 2021-12-21 06:26:53 +01:00
2 changed files with 19 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ INCREMENTAL_SEARCH, Incremental search
SCROLL_UP, Scroll up SCROLL_UP, Scroll up
SCROLL_DOWN, Scroll down SCROLL_DOWN, Scroll down
CENTER_CURSOR, Center the cursor
MOVE_UP, Move selection up MOVE_UP, Move selection up
MOVE_DOWN, Move selection down MOVE_DOWN, Move selection down

View File

@@ -2212,6 +2212,19 @@ app_ensure_selection_visible (void)
app_scroll (too_low); app_scroll (too_low);
} }
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 static bool
app_move_selection (int diff) app_move_selection (int diff)
{ {
@@ -2356,7 +2369,7 @@ incremental_search_match (const ucs4_t *needle, size_t len,
{ {
size_t i = 0; size_t i = 0;
for (; i < len && start + i < row->chars_len; i++) for (; i < len && start + i < row->chars_len; i++)
if (uc_tolower(needle[i]) != uc_tolower(row->chars[start + i].c)) if (uc_tolower (needle[i]) != uc_tolower (row->chars[start + i].c))
break; break;
best = MAX (best, i); best = MAX (best, i);
} }
@@ -2509,9 +2522,10 @@ app_process_action (enum action action)
case ACTION_PULSE_MUTE: return pulse_volume_mute (&g.pulse); case ACTION_PULSE_MUTE: return pulse_volume_mute (&g.pulse);
#endif // WITH_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_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: case ACTION_GOTO_TOP:
if (tab->item_count) if (tab->item_count)
@@ -2737,6 +2751,7 @@ g_normal_defaults[] =
{ "C-f", ACTION_GOTO_PAGE_NEXT }, { "C-f", ACTION_GOTO_PAGE_NEXT },
{ "C-y", ACTION_SCROLL_UP }, { "C-y", ACTION_SCROLL_UP },
{ "C-e", ACTION_SCROLL_DOWN }, { "C-e", ACTION_SCROLL_DOWN },
{ "z", ACTION_CENTER_CURSOR },
{ "H", ACTION_GOTO_VIEW_TOP }, { "H", ACTION_GOTO_VIEW_TOP },
{ "M", ACTION_GOTO_VIEW_CENTER }, { "M", ACTION_GOTO_VIEW_CENTER },