]> git.mdlowis.com Git - projs/tide.git/commitdiff
added logic to handle mouse movement outside of selected region
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 8 Oct 2018 02:24:56 +0000 (22:24 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 8 Oct 2018 02:24:56 +0000 (22:24 -0400)
TODO.md
lib/x11.c

diff --git a/TODO.md b/TODO.md
index c70c3b0bc3c6d2087ff007b3888ba27a9f7c7531..429238594db73b4867847ea949e620b03759869e 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -9,7 +9,6 @@
 * implement tctl command
 * implement mouse warping on search, jump to line, and focus change
 * gap buffer does not handle UTF-8 currently
-* mouse selection handling when mouse moves outside region
 * Line - Get the current line number(s) containing the selection
 * refactor selection handling to avoid swapping manually (use buf_selbeg and buf_selend)
 * encode EOL setting in log entries?
index 54f57a531482fa14b3242e293dc9b5a6b68a667e..06f19dcff24cb4ac12c004b506b1f7a4b3245110 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -91,8 +91,14 @@ static void font_load(char* name) {
 static void get_position(WinRegion id, int x, int y, size_t* row, size_t* col) {
     int starty = (id == EDIT ? Divider+3 : 0);
     int startx = ScrollWidth+3;
+    int maxy = (id == EDIT
+        ? (Divider + (win_view(EDIT)->nrows * X.font->height))
+        : Divider - 4
+    );
+    x = (x < 0 ? 0 : (x > X.width ? X.width : x));
+    y = (y < starty ? starty : (y > maxy ? maxy : y));
     *row = (y - starty) / X.font->height;
-    *col = x - startx;
+    *col = (startx <= x ? x - startx : 0);
 }
 
 static struct XSel* selfetch(Atom atom) {