Ensure positions are always sorted when rendering
This commit is contained in:
parent
dea6e1da42
commit
d8410dff24
2 changed files with 16 additions and 5 deletions
|
|
@ -134,7 +134,7 @@ func (h *Handler) draw_column_of_matches(matches []*ResultItem, current_idx int,
|
|||
} else {
|
||||
h.lp.QueueWriteString(icon + " ")
|
||||
}
|
||||
h.render_match_with_positions(text, add_ellipsis, m.positions, is_current)
|
||||
h.render_match_with_positions(text, add_ellipsis, m.sorted_positions(), is_current)
|
||||
h.lp.MoveCursorVertically(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,16 +19,27 @@ import (
|
|||
var _ = fmt.Print
|
||||
|
||||
type ResultItem struct {
|
||||
text, abspath string
|
||||
dir_entry os.DirEntry
|
||||
positions []int // may be nil
|
||||
score float64
|
||||
text, abspath string
|
||||
dir_entry os.DirEntry
|
||||
positions []int // may be nil
|
||||
score float64
|
||||
positions_sorted bool
|
||||
}
|
||||
|
||||
func (r ResultItem) String() string {
|
||||
return fmt.Sprintf("{text: %#v, abspath: %#v, is_dir: %v, positions: %#v}", r.text, r.abspath, r.dir_entry.IsDir(), r.positions)
|
||||
}
|
||||
|
||||
func (r *ResultItem) sorted_positions() []int {
|
||||
if !r.positions_sorted {
|
||||
r.positions_sorted = true
|
||||
if len(r.positions) > 1 {
|
||||
sort.Ints(r.positions)
|
||||
}
|
||||
}
|
||||
return r.positions
|
||||
}
|
||||
|
||||
type dir_cache map[string][]os.DirEntry
|
||||
|
||||
type ScanCache struct {
|
||||
|
|
|
|||
Loading…
Reference in a new issue