From c0f0d914c04b654105021964cc53ea8511a1ca08 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 7 Oct 2018 22:24:56 -0400 Subject: [PATCH] added logic to handle mouse movement outside of selected region --- TODO.md | 1 - lib/x11.c | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index c70c3b0..4292385 100644 --- 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? diff --git a/lib/x11.c b/lib/x11.c index 54f57a5..06f19dc 100644 --- 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) { -- 2.52.0