From 93ae6e962fa9d126a7d3e96c8608539fe6bb8dc3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 Jul 2023 12:56:02 +0530 Subject: [PATCH] Fix infinite loop in text for current mouse selection --- kittens/diff/mouse.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kittens/diff/mouse.go b/kittens/diff/mouse.go index f3c328674..674e5d485 100644 --- a/kittens/diff/mouse.go +++ b/kittens/diff/mouse.go @@ -10,6 +10,7 @@ import ( "kitty" "kitty/tools/config" + "kitty/tools/tty" "kitty/tools/tui" "kitty/tools/tui/loop" "kitty/tools/utils" @@ -110,6 +111,8 @@ func (self *Handler) drag_scroll_tick(timer_id loop.IdType) error { }) } +var debugprintln = tty.DebugPrintln + func (self *Handler) update_mouse_selection(ev *loop.MouseEvent) { if !self.mouse_selection.IsActive() { return @@ -151,7 +154,7 @@ func (self *Handler) text_for_current_mouse_selection() string { return self.logical_lines.ScreenLineAt(pos).right.marked_up_text } - for pos, prev_ll_idx := start, start.logical_line; pos.Less(end) || pos == end; self.logical_lines.IncrementScrollPosBy(&pos, 1) { + for pos, prev_ll_idx := start, start.logical_line; pos.Less(end) || pos == end; { ll := self.logical_lines.At(pos.logical_line) var line string switch ll.line_type { @@ -180,6 +183,9 @@ func (self *Handler) text_for_current_mouse_selection() string { if line != "" { text = append(text, line...) } + if self.logical_lines.IncrementScrollPosBy(&pos, 1) == 0 { + break + } } return utils.UnsafeBytesToString(text) }