shithub: orca

Download patch

ref: cb32eaa7b406d6dcff63f2b2da7bf0b9006655aa
parent: f420ec5e6c3d1b70a83d7d24029c883300f0575c
parent: 906b114c7651088d24d6cdca32b7f13db9b8a4cc
author: Nicola Pisanti <nicola@npisanti.com>
date: Mon Jun 10 08:05:32 EDT 2019

Merge pull request #45 from attejensen/ruler_jumps

Ctrl makes cursor jump according to ruler spacing

Only works in some terminals.

--- a/tui_main.c
+++ b/tui_main.c
@@ -1248,7 +1248,7 @@
   a->is_draw_dirty = true;
 }
 
-Usz guarded_selection_axis_resize(Usz x, int delta) {
+Usz guarded_selection_axis_resize(Usz x, Isz delta) {
   if (delta < 0) {
     if (delta > INT_MIN && (Usz)(-delta) < x) {
       x -= (Usz)(-delta);
@@ -1259,7 +1259,7 @@
   return x;
 }
 
-void ged_modify_selection_size(Ged* a, int delta_y, int delta_x) {
+void ged_modify_selection_size(Ged* a, Isz delta_y, Isz delta_x) {
   Usz cur_h = a->ged_cursor.h;
   Usz cur_w = a->ged_cursor.w;
   Usz new_h = guarded_selection_axis_resize(cur_h, delta_y);
@@ -1278,7 +1278,7 @@
   Ged_dir_right,
 } Ged_dir;
 
-void ged_dir_input(Ged* a, Ged_dir dir) {
+void ged_dir_input(Ged* a, Ged_dir dir, Isz step_length) {
   switch (a->input_mode) {
   case Ged_input_mode_normal:
   case Ged_input_mode_append:
@@ -1285,32 +1285,33 @@
   case Ged_input_mode_piano:
     switch (dir) {
     case Ged_dir_up:
-      ged_move_cursor_relative(a, -1, 0);
+      ged_move_cursor_relative(a, -step_length, 0);
       break;
     case Ged_dir_down:
-      ged_move_cursor_relative(a, 1, 0);
+      ged_move_cursor_relative(a, step_length, 0);
       break;
     case Ged_dir_left:
-      ged_move_cursor_relative(a, 0, -1);
+      ged_move_cursor_relative(a, 0, -step_length);
       break;
     case Ged_dir_right:
-      ged_move_cursor_relative(a, 0, 1);
+      ged_move_cursor_relative(a, 0, step_length);
       break;
     }
     break;
   case Ged_input_mode_selresize:
+    // AtteJensen: This code is never reached, or?
     switch (dir) {
     case Ged_dir_up:
-      ged_modify_selection_size(a, -1, 0);
+      ged_modify_selection_size(a, -step_length, 0);
       break;
     case Ged_dir_down:
-      ged_modify_selection_size(a, 1, 0);
+      ged_modify_selection_size(a, step_length, 0);
       break;
     case Ged_dir_left:
-      ged_modify_selection_size(a, 0, -1);
+      ged_modify_selection_size(a, 0, -step_length);
       break;
     case Ged_dir_right:
-      ged_modify_selection_size(a, 0, 1);
+      ged_modify_selection_size(a, 0, step_length);
       break;
     }
   }
@@ -2335,21 +2336,21 @@
     switch (key) {
     case KEY_UP:
     case CTRL_PLUS('k'):
-      ged_dir_input(&ged_state, Ged_dir_up);
+      ged_dir_input(&ged_state, Ged_dir_up, 1);
       break;
     case CTRL_PLUS('j'):
     case KEY_DOWN:
-      ged_dir_input(&ged_state, Ged_dir_down);
+      ged_dir_input(&ged_state, Ged_dir_down, 1);
       break;
     case 127: // backspace in terminal.app, apparently
     case KEY_BACKSPACE:
     case CTRL_PLUS('h'):
     case KEY_LEFT:
-      ged_dir_input(&ged_state, Ged_dir_left);
+      ged_dir_input(&ged_state, Ged_dir_left, 1);
       break;
     case CTRL_PLUS('l'):
     case KEY_RIGHT:
-      ged_dir_input(&ged_state, Ged_dir_right);
+      ged_dir_input(&ged_state, Ged_dir_right, 1);
       break;
     case CTRL_PLUS('z'):
     case CTRL_PLUS('u'):
@@ -2435,9 +2436,35 @@
     case 402: // shift-right
       ged_modify_selection_size(&ged_state, 0, 1);
       break;
+    case 567: // shift-control-up
+      ged_modify_selection_size(&ged_state, -(Isz)ged_state.ruler_spacing_y, 0);
+      break;
+    case 526: // shift-control-down
+      ged_modify_selection_size(&ged_state, (Isz)ged_state.ruler_spacing_y, 0);
+      break;
+    case 546: // shift-control-left
+      ged_modify_selection_size(&ged_state, 0, -(Isz)ged_state.ruler_spacing_x);
+      break;
+    case 561: // shift-control-right
+      ged_modify_selection_size(&ged_state, 0, (Isz)ged_state.ruler_spacing_x);
+      break;
 
     case 330: // delete?
       ged_input_character(&ged_state, '.');
+      break;
+
+    // Jump on control-arrow
+    case 566: //control-up
+      ged_dir_input(&ged_state, Ged_dir_up, (Isz)ged_state.ruler_spacing_y);
+      break;
+    case 525: //control-down
+      ged_dir_input(&ged_state, Ged_dir_down, (Isz)ged_state.ruler_spacing_y);
+      break;
+    case 545: //control-left
+      ged_dir_input(&ged_state, Ged_dir_left, (Isz)ged_state.ruler_spacing_x);
+      break;
+    case 560: //control-right
+      ged_dir_input(&ged_state, Ged_dir_right, (Isz)ged_state.ruler_spacing_x);
       break;
 
     case CTRL_PLUS('d'):