Fix #10634
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run

This commit is contained in:
Kovid Goyal 2026-10-09 13:53:34 +05:30
parent c726b75d13
commit fb68ed81e0
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 29 additions and 7 deletions

View file

@ -234,6 +234,9 @@ Detailed list of changes
- Fix a space immediately after a tab stop being dropped when the screen
contents are copied or sent to the scrollback pager (:iss:`10609`)
- diff kitten: Fix selecting text with the mouse lagging badly when using a
mouse with a high polling rate (:iss:`10634`)
- Fix closing an unfocused window that comes before the focused window in the
layout sometimes moving focus to a different window

View file

@ -125,17 +125,18 @@ func (self *Handler) update_mouse_selection(ev *loop.MouseEvent) {
self.mouse_selection.DragScroll(ev, self.lp, self.drag_scroll_tick)
return
}
self.do_update_mouse_selection(ev)
if self.do_update_mouse_selection(ev) {
self.draw_screen()
}
}
func (self *Handler) do_update_mouse_selection(ev *loop.MouseEvent) {
func (self *Handler) do_update_mouse_selection(ev *loop.MouseEvent) (changed bool) {
pos := self.scroll_pos
y := ev.Cell.Y
y = utils.Max(0, utils.Min(y, self.screen_size.num_lines-1))
self.logical_lines.IncrementScrollPosBy(&pos, y)
x := self.mouse_selection.StartLine().MinX()
self.mouse_selection.Update(ev, self.line_pos_from_pos(x, pos))
self.draw_screen()
return self.mouse_selection.Update(ev, self.line_pos_from_pos(x, pos))
}
func (self *Handler) clear_mouse_selection() {

View file

@ -53,10 +53,24 @@ func writestring_ignoring_temporary_errors(f *tty.Term, buf string) (int, error)
return n, err
}
// Remove the first n entries from pending_writes. This must not copy the
// remaining entries, as when there are lots of small writes queued up (for
// example when redrawing the screen in response to a flood of mouse events) that
// becomes quadratic, see https://github.com/kovidgoyal/kitty/issues/10634
func (self *Loop) discard_sent_pending_writes(n int) {
clear(self.pending_writes[:n])
if n >= len(self.pending_writes) {
// reuse the underlying array
self.pending_writes = self.pending_writes[:0]
} else {
self.pending_writes = self.pending_writes[n:]
}
}
func (self *Loop) flush_pending_writes(tty_write_channel chan<- write_msg) (num_sent int) {
defer func() {
if num_sent > 0 {
self.pending_writes = utils.ShiftLeft(self.pending_writes, num_sent)
self.discard_sent_pending_writes(num_sent)
}
}()
for len(self.pending_writes) > num_sent {
@ -74,7 +88,7 @@ func (self *Loop) wait_for_write_to_complete(sentinel IdType, tty_write_channel
num_sent := 0
defer func() {
if num_sent > 0 {
self.pending_writes = utils.ShiftLeft(self.pending_writes, num_sent)
self.discard_sent_pending_writes(num_sent)
}
}()

View file

@ -78,14 +78,18 @@ func (ms *MouseSelection) StartNewSelection(ev *loop.MouseEvent, line LinePos, m
ms.is_active = true
}
func (ms *MouseSelection) Update(ev *loop.MouseEvent, line LinePos) {
// Update the end of the selection, returning true if it changed
func (ms *MouseSelection) Update(ev *loop.MouseEvent, line LinePos) (changed bool) {
ms.drag_scroll.timer_id = 0
if ms.is_active {
prev := ms.end
ms.end.x = max(line.MinX(), min(ev.Cell.X, line.MaxX()))
cell_start := ms.cell_width * ms.end.x
ms.end.in_first_half_of_cell = ev.Pixel.X <= cell_start+ms.cell_width/2
ms.end.line = line
changed = !prev.Equal(ms.end)
}
return
}
func (ms *MouseSelection) LineBounds(line_pos LinePos) (start_x, end_x int) {