@@ -65,13 +65,15 @@ func (h *Handler) draw_matching_result(r ResultItem) {
6565 h .lp .QueueWriteString (s )
6666 text := r .text
6767 available_width := (h .screen_size .width - 6 ) / 2
68+ add_ellipsis := false
6869 if wcswidth .Stringwidth (text ) > available_width {
69- text = wcswidth .TruncateToVisualLength (text , available_width - 2 ) + "…"
70+ text = wcswidth .TruncateToVisualLength (text , available_width - 2 )
71+ add_ellipsis = true
7072 }
71- h .render_match_with_positions (text , len ( r . text ) , r .positions , 2 )
73+ h .render_match_with_positions (text , add_ellipsis , r .positions , 2 )
7274}
7375
74- func (h * Handler ) render_match_with_positions (text string , stop_at int , positions []int , scale int ) {
76+ func (h * Handler ) render_match_with_positions (text string , add_ellipsis bool , positions []int , scale int ) {
7577 prefix , suffix , _ := strings .Cut (h .lp .SprintStyled (matching_position_style , " " ), " " )
7678 write_chunk := func (text string , emphasize bool ) {
7779 if text == "" {
@@ -90,7 +92,7 @@ func (h *Handler) render_match_with_positions(text string, stop_at int, position
9092 }
9193 }
9294 at := 0
93- limit := min ( stop_at , len (text ) )
95+ limit := len (text )
9496 for _ , p := range positions {
9597 if p > limit || at > limit {
9698 break
@@ -105,6 +107,9 @@ func (h *Handler) render_match_with_positions(text string, stop_at int, position
105107 if at < len (text ) {
106108 write_chunk (text [at :], false )
107109 }
110+ if add_ellipsis {
111+ write_chunk ("…" , false )
112+ }
108113}
109114
110115var icon_cache map [string ]string
@@ -130,22 +135,21 @@ func (h *Handler) draw_column_of_matches(matches []ResultItem, x, available_widt
130135 h .lp .MoveCursorHorizontally (x )
131136 icon := icon_for (m .abspath , m .dir_entry )
132137 text := ""
133- tlen := 0
138+ add_ellipsis := false
134139 positions := m .positions
135140 if num_extra_matches > 0 && i == len (matches )- 1 {
136141 icon = "… "
137142 text = h .lp .SprintStyled ("italic" , fmt .Sprintf ("%d more matches" , num_extra_matches ))
138143 positions = nil
139144 } else {
140145 text = m .text
141- tlen = len (text )
142146 if wcswidth .Stringwidth (text ) > available_width - 3 {
143- text = wcswidth .TruncateToVisualLength (text , available_width - 4 ) + "…"
144- tlen = len ( text ) - 1
147+ text = wcswidth .TruncateToVisualLength (text , available_width - 4 )
148+ add_ellipsis = true
145149 }
146150 }
147151 h .lp .QueueWriteString (icon + " " )
148- h .render_match_with_positions (text , tlen , positions , 1 )
152+ h .render_match_with_positions (text , add_ellipsis , positions , 1 )
149153 h .lp .MoveCursorVertically (1 )
150154 }
151155}
0 commit comments