Merge branch 'fix/diff-search-eol' of https://github.com/4RH1T3CT0R7/kitty

This commit is contained in:
Kovid Goyal 2026-09-28 06:43:01 +05:30
commit c355c40199
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 42 additions and 1 deletions

View file

@ -239,6 +239,8 @@ Detailed list of changes
- macOS: Fix a custom dock icon reverting to the stock icon after a progress
bar is cleared (:iss:`10545`)
- diff kitten: Fix search not finding matches at the end of a line
0.49.1 [2026-09-24]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -57,7 +57,7 @@ func (self *Search) find_matches_in_lines(clean_lines []string, origin int, send
}
start_line := find_pos(start)
if start_line > -1 {
end_line := find_pos(end)
end_line := find_pos(end - 1)
if end_line > -1 {
for i := start_line; i <= end_line; i++ {
cell_start := 0

View file

@ -0,0 +1,39 @@
// License: GPLv3 Copyright: 2026, Kovid Goyal, <kovid at kovidgoyal.net>
package diff
import (
"regexp"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestDiffSearchFindMatches(t *testing.T) {
wrapped := []string{"abc def ", "ghi rows"}
for _, tc := range []struct {
pat string
lines []string
origin int
expected [][3]int
}{
{"foo", []string{"x := foo"}, 0, [][3]int{{0, 5, 3}}},
{"o", []string{"foo"}, 0, [][3]int{{0, 1, 1}, {0, 2, 1}}},
{"rows", wrapped, 0, [][3]int{{1, 4, 4}}},
{"def ghi", wrapped, 0, [][3]int{{0, 4, 4}, {1, 0, 3}}},
{"def ", wrapped, 0, [][3]int{{0, 4, 4}}},
{"foo", []string{"日本 foo"}, 0, [][3]int{{0, 5, 3}}},
{"foo", []string{"x := foo"}, 7, [][3]int{{0, 12, 3}}},
} {
s := &Search{pat: regexp.MustCompile(tc.pat)}
var actual [][3]int
s.find_matches_in_lines(tc.lines, tc.origin, func(screen_line, offset, size int) {
if size > 0 {
actual = append(actual, [3]int{screen_line, offset, size})
}
})
if diff := cmp.Diff(tc.expected, actual); diff != "" {
t.Errorf("Unexpected matches for %#v in %#v:\n%s", tc.pat, tc.lines, diff)
}
}
}