@@ -115,7 +115,7 @@ func icon_for(path string, x os.DirEntry) string {
115115 return ans
116116}
117117
118- func (h * Handler ) draw_column_of_matches (matches []* ResultItem , current_idx int , x , available_width int , is_last bool , num_before , num_after int ) {
118+ func (h * Handler ) draw_column_of_matches (matches []* ResultItem , current_idx int , x , available_width int ) {
119119 for i , m := range matches {
120120 h .lp .QueueWriteString ("\r " )
121121 h .lp .MoveCursorHorizontally (x )
@@ -135,25 +135,11 @@ func (h *Handler) draw_column_of_matches(matches []*ResultItem, current_idx int,
135135 h .render_match_with_positions (text , add_ellipsis , m .positions , is_current )
136136 h .lp .MoveCursorVertically (1 )
137137 }
138- if is_last && num_after + num_before > 0 {
139- h .lp .QueueWriteString ("\r " )
140- h .lp .MoveCursorHorizontally (x )
141- h .lp .QueueWriteString ("… " )
142- text := ""
143- if num_before > 0 {
144- text = fmt .Sprintf ("%d before, %d after" , num_before , num_after )
145- } else {
146- text = fmt .Sprintf ("%d more matches" , num_after )
147- }
148- text = h .lp .SprintStyled ("italic" , text )
149- h .render_match_with_positions (text , false , nil , false )
150- h .lp .MoveCursorVertically (1 )
151- }
152138}
153139
154- func (h * Handler ) draw_list_of_results (matches []* ResultItem , y , height int ) {
140+ func (h * Handler ) draw_list_of_results (matches []* ResultItem , y , height int ) int {
155141 if len (matches ) == 0 || height < 2 {
156- return
142+ return 0
157143 }
158144 available_width := h .screen_size .width - 2
159145 col_width := available_width
@@ -168,33 +154,23 @@ func (h *Handler) draw_list_of_results(matches []*ResultItem, y, height int) {
168154 }
169155 num_of_slots := num_cols * height
170156 idx := min (h .state .CurrentIndex (), len (matches )- 1 )
171- has_more := len ( matches ) > num_of_slots
172- if has_more {
173- num_of_slots -- // need one slot for X more matches msg
157+ pos := 0
158+ for pos + num_of_slots <= idx {
159+ pos += height
174160 }
175- pos := max (0 , idx + 1 - num_of_slots )
176- num_before := pos
177- num_after := max (0 , len (matches )- num_of_slots - num_before )
178161 x , limit , total := 1 , 0 , 0
179- for i := range num_cols {
180- is_last := i == num_cols - 1
181- num := height
182- if is_last && has_more {
183- num --
184- }
162+ for range num_cols {
185163 h .lp .MoveCursorTo (x , y )
186- limit = min (len (matches ), pos + num )
164+ limit = min (len (matches ), pos + height )
187165 total += limit - pos
188- h .draw_column_of_matches (matches [pos :limit ], idx - pos , x , col_width - 1 , is_last , num_before , num_after )
166+ h .draw_column_of_matches (matches [pos :limit ], idx - pos , x , col_width - 1 )
189167 x += col_width
190- pos += num
168+ pos += height
191169 if pos >= len (matches ) {
192170 break
193171 }
194172 }
195- if total + num_before + num_after != len (matches ) {
196- panic (fmt .Sprintf ("Did not account for all matches, internal error. total_drawn=%d num_before=%d num_after=%d total=%d" , total , num_before , num_after , len (matches )))
197- }
173+ return num_cols
198174}
199175
200176func (h * Handler ) draw_results (y , bottom_margin int , matches []* ResultItem , in_progress bool ) (height int ) {
@@ -206,13 +182,24 @@ func (h *Handler) draw_results(y, bottom_margin int, matches []*ResultItem, in_p
206182 y += 2
207183 h .lp .MoveCursorTo (1 , y )
208184 h .state .num_of_slots_per_column_at_last_render = height - 2
185+ num_cols := 0
209186 switch len (matches ) {
210187 case 0 :
211188 h .draw_no_matches_message (in_progress )
212189 default :
213- h .draw_list_of_results (matches , y , h .state .num_of_slots_per_column_at_last_render )
190+ num_cols = h .draw_list_of_results (matches , y , h .state .num_of_slots_per_column_at_last_render )
214191 }
215192 h .state .num_of_matches_at_last_render = len (matches )
193+ m := ""
194+ switch h .state .num_of_matches_at_last_render {
195+ case 0 :
196+ m = " no matches "
197+ default :
198+ m = fmt .Sprintf (" %d of %d matches " , h .state .num_of_slots_per_column_at_last_render * num_cols , h .state .num_of_matches_at_last_render )
199+ }
200+ w := wcswidth .Stringwidth (m )
201+ h .lp .MoveCursorTo (h .screen_size .width - w - 2 , y + height - 2 )
202+ h .lp .PrintStyled ("dim" , m )
216203 return
217204}
218205
@@ -253,10 +240,10 @@ func (h *Handler) handle_result_list_keys(ev *loop.KeyEvent) bool {
253240 case ev .MatchesPressOrRepeat ("up" ):
254241 h .next_result (- 1 )
255242 return true
256- case ev .MatchesPressOrRepeat ("left" ):
243+ case ev .MatchesPressOrRepeat ("left" ) || ev . MatchesPressOrRepeat ( "pgup" ) :
257244 h .move_sideways (true )
258245 return true
259- case ev .MatchesPressOrRepeat ("right" ):
246+ case ev .MatchesPressOrRepeat ("right" ) || ev . MatchesPressOrRepeat ( "pgdn" ) :
260247 h .move_sideways (false )
261248 return true
262249 default :
0 commit comments