From 277dea647e81554a6fc27f8d6160fd0c768c9ec9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 28 Mar 2023 10:29:45 +0530 Subject: [PATCH] More work on mouse selection --- kittens/diff/mouse.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kittens/diff/mouse.go b/kittens/diff/mouse.go index 31f212c32..ac561c2d4 100644 --- a/kittens/diff/mouse.go +++ b/kittens/diff/mouse.go @@ -15,8 +15,9 @@ import ( var _ = fmt.Print type SelectionBoundary struct { - line ScrollPos - x int + line ScrollPos + x int + in_first_half_of_cell bool } type MouseSelection struct { @@ -25,6 +26,8 @@ type MouseSelection struct { min_x, max_x int } +func (self *MouseSelection) IsEmpty() bool { return self.start == self.end } + type KittyOpts struct { Wheel_scroll_multiplier int } @@ -81,6 +84,8 @@ func (self *Handler) start_mouse_selection(ev *loop.MouseEvent) { ms.max_x += available_cols } ms.start.x = utils.Max(ms.min_x, utils.Min(ms.start.x, ms.max_x)) + cell_start := self.screen_size.cell_width * ev.Cell.X + ms.start.in_first_half_of_cell = ev.Pixel.X <= cell_start+self.screen_size.cell_width/2 ms.end = ms.start ms.is_active = true @@ -97,6 +102,8 @@ func (self *Handler) update_mouse_selection(ev *loop.MouseEvent) { self.logical_lines.IncrementScrollPosBy(&pos, y) ms.end.x = ev.Cell.X ms.end.x = utils.Max(ms.min_x, utils.Min(ms.end.x, ms.max_x)) + cell_start := self.screen_size.cell_width * ms.end.x + ms.end.in_first_half_of_cell = ev.Pixel.X <= cell_start+self.screen_size.cell_width/2 ms.end.line = pos self.draw_screen() } @@ -121,7 +128,7 @@ func format_part_of_line(sgr string, start_x, end_x, y int) string { func (self *Handler) add_mouse_selection_to_line(line string, line_pos ScrollPos, y int) string { ms := &self.mouse_selection - if !ms.is_active { + if ms.IsEmpty() { return line } a, b := ms.start.line, ms.end.line