mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 19:21:38 +02:00
Ensure positions are always sorted when rendering
This commit is contained in:
@@ -134,7 +134,7 @@ func (h *Handler) draw_column_of_matches(matches []*ResultItem, current_idx int,
|
|||||||
} else {
|
} else {
|
||||||
h.lp.QueueWriteString(icon + " ")
|
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)
|
h.lp.MoveCursorVertically(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,16 +19,27 @@ import (
|
|||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
type ResultItem struct {
|
type ResultItem struct {
|
||||||
text, abspath string
|
text, abspath string
|
||||||
dir_entry os.DirEntry
|
dir_entry os.DirEntry
|
||||||
positions []int // may be nil
|
positions []int // may be nil
|
||||||
score float64
|
score float64
|
||||||
|
positions_sorted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r ResultItem) String() string {
|
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)
|
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 dir_cache map[string][]os.DirEntry
|
||||||
|
|
||||||
type ScanCache struct {
|
type ScanCache struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user