Skip to content

Commit 73d1d07

Browse files
committed
Implement left/right movement
1 parent 68f02fc commit 73d1d07

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

kittens/choose_files/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ type State struct {
3333
score_patterns []ScorePattern
3434
search_text string
3535

36-
current_idx int
37-
num_of_matches_at_last_render int
36+
current_idx int
37+
num_of_matches_at_last_render int
38+
num_of_slots_per_column_at_last_render int
3839
}
3940

4041
func (s State) BaseDir() string { return utils.IfElse(s.base_dir == "", default_cwd, s.base_dir) }

kittens/choose_files/results.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ func (h *Handler) draw_results(y, bottom_margin int, matches []*ResultItem, in_p
205205
h.draw_results_title()
206206
y += 2
207207
h.lp.MoveCursorTo(1, y)
208+
h.state.num_of_slots_per_column_at_last_render = height - 2
208209
switch len(matches) {
209210
case 0:
210211
h.draw_no_matches_message(in_progress)
211212
default:
212-
h.draw_list_of_results(matches, y, height-2)
213+
h.draw_list_of_results(matches, y, h.state.num_of_slots_per_column_at_last_render)
213214
}
214215
h.state.num_of_matches_at_last_render = len(matches)
215216
return
@@ -227,6 +228,23 @@ func (h *Handler) next_result(amt int) {
227228
}
228229
}
229230

231+
func (h *Handler) move_sideways(leftwards bool) {
232+
if h.state.num_of_matches_at_last_render > 0 {
233+
idx := h.state.CurrentIndex()
234+
slots := h.state.num_of_slots_per_column_at_last_render
235+
if leftwards {
236+
if idx >= slots {
237+
idx -= slots
238+
}
239+
} else {
240+
idx = min(h.state.num_of_matches_at_last_render-1, idx+slots)
241+
}
242+
if idx != h.state.CurrentIndex() {
243+
h.state.SetCurrentIndex(idx)
244+
}
245+
}
246+
}
247+
230248
func (h *Handler) handle_result_list_keys(ev *loop.KeyEvent) bool {
231249
switch {
232250
case ev.MatchesPressOrRepeat("down"):
@@ -235,6 +253,12 @@ func (h *Handler) handle_result_list_keys(ev *loop.KeyEvent) bool {
235253
case ev.MatchesPressOrRepeat("up"):
236254
h.next_result(-1)
237255
return true
256+
case ev.MatchesPressOrRepeat("left"):
257+
h.move_sideways(true)
258+
return true
259+
case ev.MatchesPressOrRepeat("right"):
260+
h.move_sideways(false)
261+
return true
238262
default:
239263
return false
240264
}

0 commit comments

Comments
 (0)