Skip to content

Commit 591473d

Browse files
committed
Fix #8997
1 parent ee00bfa commit 591473d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

kittens/choose_files/results.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"runtime"
1010
"strings"
11-
"unicode/utf8"
1211

1312
"github.com/kovidgoyal/kitty/tools/icons"
1413
"github.com/kovidgoyal/kitty/tools/tui"
@@ -84,20 +83,19 @@ func (h *Handler) render_match_with_positions(text string, add_ellipsis bool, po
8483
h.lp.QueueWriteString(text)
8584
}
8685
at := 0
87-
limit := len(text)
86+
runes := []rune(text)
87+
limit := len(runes)
8888
for _, p := range positions {
89-
if p > limit || at > limit {
89+
if p >= limit || at >= limit || p <= at {
9090
break
9191
}
92-
write_chunk(text[at:p], false)
93-
at = p
94-
if r, sz := utf8.DecodeRuneInString(text[p:]); r != utf8.RuneError {
95-
write_chunk(string(r), true)
96-
at += sz
97-
}
92+
before := runes[at:p]
93+
write_chunk(string(before), false)
94+
write_chunk(string(runes[p]), true)
95+
at = p + 1
9896
}
99-
if at < len(text) {
100-
write_chunk(text[at:], false)
97+
if at < len(runes) {
98+
write_chunk(string(runes[at:]), false)
10199
}
102100
if add_ellipsis {
103101
write_chunk("…", false)

0 commit comments

Comments
 (0)