summaryrefslogtreecommitdiff
path: root/src/merger.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-03-29 20:36:09 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-04-01 12:59:44 +0900
commit1c7534f00966edca7c44054af199ca27aca0a80c (patch)
tree58ec99c05fc552f69ce05dc8160d70324254e6fd /src/merger.go
parentae745d9397bdc8b91f3c1834def3b8ecb0ae57b1 (diff)
downloadfzf-1c7534f00966edca7c44054af199ca27aca0a80c.tar.gz
Add --track option to track the current selection
Close #3186 Related #1890
Diffstat (limited to 'src/merger.go')
-rw-r--r--src/merger.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/merger.go b/src/merger.go
index 8e6a884c..cdf00acc 100644
--- a/src/merger.go
+++ b/src/merger.go
@@ -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 {