From e67066d80f46964d1d5af7bcc82a382164552d3d Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 17 Jan 2017 15:47:36 +0100
Subject: Add actions to jump by fields
---
hex.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
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, {}},
};
--
cgit v1.2.3-70-g09d2