summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-02-26 00:24:41 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-02-26 00:25:23 +0900
commit710ebdf9c14e0c88b0cfc843ce08edcdd4554571 (patch)
treedac36d7934813166ac18b61146daf2bd44a94490 /src
parentbb64d84ce407221bd0c4e219b182cfbafac0bed7 (diff)
downloadfzf-710ebdf9c14e0c88b0cfc843ce08edcdd4554571.tar.gz
Make --accept-nth compatible with --select-1
Fix #4287
Diffstat (limited to 'src')
-rw-r--r--src/core.go11
-rw-r--r--src/item.go6
-rw-r--r--src/terminal.go4
3 files changed, 17 insertions, 4 deletions
diff --git a/src/core.go b/src/core.go
index d639769d..404af12a 100644
--- a/src/core.go
+++ b/src/core.go
@@ -476,8 +476,17 @@ func Run(opts *Options) (int, error) {
if len(opts.Expect) > 0 {
opts.Printer("")
}
+ transformer := func(item *Item) string {
+ return item.AsString(opts.Ansi)
+ }
+ if opts.AcceptNth != nil {
+ fn := opts.AcceptNth(opts.Delimiter)
+ transformer = func(item *Item) string {
+ return item.acceptNth(opts.Ansi, opts.Delimiter, fn)
+ }
+ }
for i := 0; i < count; i++ {
- opts.Printer(val.Get(i).item.AsString(opts.Ansi))
+ opts.Printer(transformer(val.Get(i).item))
}
if count == 0 {
exitCode = ExitNoMatch
diff --git a/src/item.go b/src/item.go
index ca32f1bd..19f0498e 100644
--- a/src/item.go
+++ b/src/item.go
@@ -51,3 +51,9 @@ func (item *Item) AsString(stripAnsi bool) string {
}
return item.text.ToString()
}
+
+func (item *Item) acceptNth(stripAnsi bool, delimiter Delimiter, transformer func([]Token, int32) string) string {
+ tokens := Tokenize(item.AsString(stripAnsi), delimiter)
+ transformed := transformer(tokens, item.Index())
+ return StripLastDelimiter(transformed, delimiter)
+}
diff --git a/src/terminal.go b/src/terminal.go
index a762853e..2f00a398 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -1575,9 +1575,7 @@ func (t *Terminal) output() bool {
}
if t.acceptNth != nil {
transform = func(item *Item) string {
- tokens := Tokenize(item.AsString(t.ansi), t.delimiter)
- transformed := t.acceptNth(tokens, item.Index())
- return StripLastDelimiter(transformed, t.delimiter)
+ return item.acceptNth(t.ansi, t.delimiter, t.acceptNth)
}
}
found := len(t.selected) > 0