summaryrefslogtreecommitdiffstats
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
parent44cfc7e62a44e06fb419a6d87e8f80bb7a8281cd (diff)
Fixed --track when used with --tac
Fix #3234
-rw-r--r--CHANGELOG.md4
-rw-r--r--man/man1/fzf.11
-rw-r--r--src/merger.go25
-rw-r--r--src/options.go6
-rw-r--r--src/terminal.go8
5 files changed, 30 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c16db6a..ec087b0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,7 +3,9 @@ CHANGELOG
0.39.1
------
-- Disallow using `--track` with `--tac` as the result can be very confusing
+- Fixed `--track` behavior when used with `--tac`
+ - However, using `--track` with `--tac` is not recommended. The resulting
+ behavior can be very confusing.
- Bug fixes and improvements
0.39.0
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1
index d632a4ce..4bb29bc4 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -95,7 +95,6 @@ Do not sort the result
.B "--track"
Make fzf track the current selection when the result list is updated.
This can be useful when browsing logs using fzf with sorting disabled.
-This option is not compatible with \fB--tac\fR.
.RS
e.g.
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
diff --git a/src/options.go b/src/options.go
index 071819d9..e09e9b59 100644
--- a/src/options.go
+++ b/src/options.go
@@ -1083,6 +1083,8 @@ func parseActionList(masked string, original string, prevActions []*action, putA
appendAction(actToggleAll)
case "toggle-search":
appendAction(actToggleSearch)
+ case "toggle-track":
+ appendAction(actToggleTrack)
case "select":
appendAction(actSelect)
case "select-all":
@@ -1938,10 +1940,6 @@ func postProcessOptions(opts *Options) {
errorExit("scrollbar display width should be 1")
}
- if opts.Track && opts.Tac {
- errorExit("--track cannot be used with --tac")
- }
-
// Default actions for CTRL-N / CTRL-P when --history is set
if opts.History != nil {
if _, prs := opts.Keymap[tui.CtrlP.AsEvent()]; !prs {
diff --git a/src/terminal.go b/src/terminal.go
index 5ecba97b..cbbde9c5 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -907,8 +907,12 @@ func (t *Terminal) UpdateProgress(progress float32) {
func (t *Terminal) UpdateList(merger *Merger, reset bool) {
t.mutex.Lock()
var prevIndex int32 = -1
- if !reset && t.track && t.merger.Length() > 0 {
- prevIndex = t.merger.Get(t.cy).item.Index()
+ if !reset && t.track {
+ if t.merger.Length() > 0 {
+ prevIndex = t.merger.Get(t.cy).item.Index()
+ } else if merger.Length() > 0 {
+ prevIndex = merger.First().item.Index()
+ }
}
t.progress = 100
t.merger = merger