m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-15 23:03:47 -05:00

Add --track option to track the current selection

Close #3186
Related #1890
This commit is contained in:
Junegunn Choi
2023-03-29 20:36:09 +09:00
parent ae745d9397
commit 1c7534f009
6 changed files with 81 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ type Merger struct {
tac bool
final bool
count int
pass bool
}
// PassMerger returns a new Merger that simply returns the items in the
@@ -26,7 +27,8 @@ func PassMerger(chunks *[]*Chunk, tac bool) *Merger {
pattern: nil,
chunks: chunks,
tac: tac,
count: 0}
count: 0,
pass: true}
for _, chunk := range *mg.chunks {
mg.count += chunk.count
@@ -58,6 +60,19 @@ func (mg *Merger) Length() int {
return mg.count
}
// FindIndex returns the index of the item with the given item index
func (mg *Merger) FindIndex(itemIndex int32) int {
if mg.pass {
return int(itemIndex)
}
for i := 0; i < mg.count; i++ {
if mg.Get(i).item.Index() == itemIndex {
return i
}
}
return -1
}
// Get returns the pointer to the Result object indexed by the given integer
func (mg *Merger) Get(idx int) Result {
if mg.chunks != nil {