aboutsummaryrefslogtreecommitdiff
path: root/hex.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-01-17 15:47:36 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2017-01-17 16:02:38 +0100
commite67066d80f46964d1d5af7bcc82a382164552d3d (patch)
tree8195a0edbfe144763f043d4b0c42b4c6fcf5ab86 /hex.c
parent1aa043324cf848443dee961be50e67391f1fdff2 (diff)
downloadhex-e67066d80f46964d1d5af7bcc82a382164552d3d.tar.gz
hex-e67066d80f46964d1d5af7bcc82a382164552d3d.tar.xz
hex-e67066d80f46964d1d5af7bcc82a382164552d3d.zip
Add actions to jump by fields
Diffstat (limited to 'hex.c')
-rw-r--r--hex.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/hex.c b/hex.c
index fded810..3d9c13f 100644
--- a/hex.c
+++ b/hex.c
@@ -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, {}},
};