shithub: orca

Download patch

ref: 66c1e7990b7ac332b7bac0fc475e3591b64fd4f7
parent: 7bd17f61f98baa021c9c9596dabd356c0a5395ce
author: cancel <cancel@cancel.fm>
date: Mon Dec 10 20:46:11 EST 2018

Fix mouse hitting when scrolled

--- a/tui_main.c
+++ b/tui_main.c
@@ -994,10 +994,29 @@
   a->is_draw_dirty = true;
 }
 
+Usz confine_scrolled_mouse_hit(Usz field_len, Usz visual_coord,
+                               int scroll_offset) {
+  if (field_len == 0)
+    return 0;
+  if (scroll_offset < 0) {
+    if ((Usz)(-scroll_offset) <= visual_coord) {
+      visual_coord -= (Usz)(-scroll_offset);
+    } else {
+      visual_coord = 0;
+    }
+  } else {
+    visual_coord += (Usz)scroll_offset;
+  }
+  if (visual_coord > field_len)
+    visual_coord = field_len - 1;
+  return visual_coord;
+}
+
 void app_jump_cursor_to(App_state* a, Usz y, Usz x) {
-  a->tui_cursor.y = y;
-  a->tui_cursor.x = x;
-  tui_cursor_confine(&a->tui_cursor, a->field.height, a->field.width);
+  a->tui_cursor.y =
+      confine_scrolled_mouse_hit(a->field.height, y, a->grid_scroll_y);
+  a->tui_cursor.x =
+      confine_scrolled_mouse_hit(a->field.width, x, a->grid_scroll_x);
   a->is_draw_dirty = true;
 }