diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2017-01-17 15:47:36 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2017-01-17 16:02:38 +0100 |
commit | e67066d80f46964d1d5af7bcc82a382164552d3d (patch) | |
tree | 8195a0edbfe144763f043d4b0c42b4c6fcf5ab86 | |
parent | 1aa043324cf848443dee961be50e67391f1fdff2 (diff) | |
download | hex-e67066d80f46964d1d5af7bcc82a382164552d3d.tar.gz hex-e67066d80f46964d1d5af7bcc82a382164552d3d.tar.xz hex-e67066d80f46964d1d5af7bcc82a382164552d3d.zip |
Add actions to jump by fields
-rw-r--r-- | hex.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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, {}}, }; |