From 1c7534f00966edca7c44054af199ca27aca0a80c Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 29 Mar 2023 20:36:09 +0900 Subject: Add --track option to track the current selection Close #3186 Related #1890 --- src/merger.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/merger.go') 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 { -- cgit v1.2.3