Add actions to jump by fields

This commit is contained in:
Přemysl Eric Janouch 2017-01-17 15:47:36 +01:00
parent 1aa043324c
commit e67066d80f
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 29 additions and 0 deletions

29
hex.c
View File

@ -1345,6 +1345,19 @@ app_move_cursor_by_rows (int diff)
return result;
}
static bool
app_jump_to_marks (ssize_t i)
{
if (i < 0 || (size_t) i >= g_ctx.marks_by_offset_len)
return false;
g_ctx.view_cursor = g_ctx.marks_by_offset[i].offset;
g_ctx.view_skip_nibble = false;
app_invalidate ();
app_ensure_selection_visible ();
return true;
}
// --- User input handling -----------------------------------------------------
enum action
@ -1356,6 +1369,8 @@ enum action
ACTION_UP, ACTION_DOWN, ACTION_LEFT, ACTION_RIGHT,
ACTION_FIELD_PREVIOUS, ACTION_FIELD_NEXT,
ACTION_COUNT
};
@ -1427,6 +1442,17 @@ app_process_action (enum action action)
app_invalidate ();
break;
case ACTION_FIELD_PREVIOUS:
{
ssize_t i = app_find_marks (g_ctx.view_cursor);
if (i >= 0 && (size_t) i < g_ctx.marks_by_offset_len
&& g_ctx.marks_by_offset[i].offset == g_ctx.view_cursor)
i--;
return app_jump_to_marks (i);
}
case ACTION_FIELD_NEXT:
return app_jump_to_marks (app_find_marks (g_ctx.view_cursor) + 1);
case ACTION_QUIT:
app_quit ();
case ACTION_NONE:
@ -1539,6 +1565,9 @@ g_default_bindings[] =
{ "C-p", ACTION_UP, {}},
{ "C-n", ACTION_DOWN, {}},
{ "b", ACTION_FIELD_PREVIOUS, {}},
{ "w", ACTION_FIELD_NEXT, {}},
{ "C-y", ACTION_SCROLL_UP, {}},
{ "C-e", ACTION_SCROLL_DOWN, {}},
};