shithub: orca

Download patch

ref: 7a27b6ed75a5a9916c458f009e0c23f04a7313c5
parent: aca5738e698613f5ad0320b6123096d023531b40
author: cancel <cancel@cancel.fm>
date: Tue Dec 11 14:46:39 EST 2018

Split off movement handling

--- a/tui_main.c
+++ b/tui_main.c
@@ -1022,6 +1022,30 @@
   a->is_draw_dirty = true;
 }
 
+typedef enum {
+  App_dir_up,
+  App_dir_down,
+  App_dir_left,
+  App_dir_right,
+} App_dir;
+
+void app_dir_input(App_state* a, App_dir dir) {
+  switch (dir) {
+    case App_dir_up:
+      app_move_cursor_relative(a, -1, 0);
+      break;
+    case App_dir_down:
+      app_move_cursor_relative(a, 1, 0);
+      break;
+    case App_dir_left:
+      app_move_cursor_relative(a, 0, -1);
+      break;
+    case App_dir_right:
+      app_move_cursor_relative(a, 0, 1);
+      break;
+  }
+}
+
 Usz view_to_scrolled_grid(Usz field_len, Usz visual_coord, int scroll_offset) {
   if (field_len == 0)
     return 0;
@@ -1570,20 +1594,20 @@
       goto quit;
     case KEY_UP:
     case AND_CTRL('k'):
-      app_move_cursor_relative(&app_state, -1, 0);
+      app_dir_input(&app_state, App_dir_up);
       break;
     case AND_CTRL('j'):
     case KEY_DOWN:
-      app_move_cursor_relative(&app_state, 1, 0);
+      app_dir_input(&app_state, App_dir_down);
       break;
     case KEY_BACKSPACE:
     case AND_CTRL('h'):
     case KEY_LEFT:
-      app_move_cursor_relative(&app_state, 0, -1);
+      app_dir_input(&app_state, App_dir_left);
       break;
     case AND_CTRL('l'):
     case KEY_RIGHT:
-      app_move_cursor_relative(&app_state, 0, 1);
+      app_dir_input(&app_state, App_dir_right);
       break;
     case AND_CTRL('z'):
     case AND_CTRL('u'):