summaryrefslogtreecommitdiff
path: root/src/merger.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-04-22 15:06:22 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-04-22 15:09:43 +0900
commit7c6f5dba63a4cf54a785090c26479003118f0046 (patch)
tree31356868f491c54e26b745d99bd59b44df3b7997 /src/merger.go
parent44cfc7e62a44e06fb419a6d87e8f80bb7a8281cd (diff)
downloadfzf-7c6f5dba63a4cf54a785090c26479003118f0046.tar.gz
Fixed --track when used with --tac
Fix #3234
Diffstat (limited to 'src/merger.go')
-rw-r--r--src/merger.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/merger.go b/src/merger.go
index cdf00acc..5c12575c 100644
--- a/src/merger.go
+++ b/src/merger.go
@@ -60,17 +60,30 @@ func (mg *Merger) Length() int {
return mg.count
}
+func (mg *Merger) First() Result {
+ if mg.tac && !mg.sorted {
+ return mg.Get(mg.count - 1)
+ }
+ return mg.Get(0)
+}
+
// FindIndex returns the index of the item with the given item index
func (mg *Merger) FindIndex(itemIndex int32) int {
+ index := -1
if mg.pass {
- return int(itemIndex)
- }
- for i := 0; i < mg.count; i++ {
- if mg.Get(i).item.Index() == itemIndex {
- return i
+ index = int(itemIndex)
+ if mg.tac {
+ index = mg.count - index - 1
+ }
+ } else {
+ for i := 0; i < mg.count; i++ {
+ if mg.Get(i).item.Index() == itemIndex {
+ index = i
+ break
+ }
}
}
- return -1
+ return index
}
// Get returns the pointer to the Result object indexed by the given integer