Skip to content

Commit c77e233

Browse files
committed
Fix --accept-nth being ignored in filter mode
The --accept-nth option was not being respected when using --filter mode. This caused fzf to output entire lines instead of only the specified fields. Added buildItemTransformer() helper function to consistently apply field transformations across filter mode (both streaming and non-streaming) and select1/exit0 modes. Fixes #4615
1 parent b3b2218 commit c77e233

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/core.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ func (r revision) compatible(other revision) bool {
3838
return r.major == other.major
3939
}
4040

41+
func buildItemTransformer(opts *Options) func(*Item) string {
42+
if opts.AcceptNth != nil {
43+
fn := opts.AcceptNth(opts.Delimiter)
44+
return func(item *Item) string {
45+
return item.acceptNth(opts.Ansi, opts.Delimiter, fn)
46+
}
47+
}
48+
return func(item *Item) string {
49+
return item.AsString(opts.Ansi)
50+
}
51+
}
52+
4153
// Run starts fzf
4254
func Run(opts *Options) (int, error) {
4355
if opts.Filter == nil {
@@ -243,6 +255,8 @@ func Run(opts *Options) (int, error) {
243255
pattern := patternBuilder([]rune(*opts.Filter))
244256
matcher.sort = pattern.sortable
245257

258+
transformer := buildItemTransformer(opts)
259+
246260
found := false
247261
if streamingFilter {
248262
slab := util.MakeSlab(slab16Size, slab32Size)
@@ -253,7 +267,7 @@ func Run(opts *Options) (int, error) {
253267
if chunkList.trans(&item, runes) {
254268
mutex.Lock()
255269
if result, _, _ := pattern.MatchItem(&item, false, slab); result != nil {
256-
opts.Printer(item.text.ToString())
270+
opts.Printer(transformer(&item))
257271
found = true
258272
}
259273
mutex.Unlock()
@@ -271,7 +285,7 @@ func Run(opts *Options) (int, error) {
271285
chunks: snapshot,
272286
pattern: pattern})
273287
for i := 0; i < result.merger.Length(); i++ {
274-
opts.Printer(result.merger.Get(i).item.AsString(opts.Ansi))
288+
opts.Printer(transformer(result.merger.Get(i).item))
275289
found = true
276290
}
277291
}
@@ -493,15 +507,7 @@ func Run(opts *Options) (int, error) {
493507
if len(opts.Expect) > 0 {
494508
opts.Printer("")
495509
}
496-
transformer := func(item *Item) string {
497-
return item.AsString(opts.Ansi)
498-
}
499-
if opts.AcceptNth != nil {
500-
fn := opts.AcceptNth(opts.Delimiter)
501-
transformer = func(item *Item) string {
502-
return item.acceptNth(opts.Ansi, opts.Delimiter, fn)
503-
}
504-
}
510+
transformer := buildItemTransformer(opts)
505511
for i := range count {
506512
opts.Printer(transformer(merger.Get(i).item))
507513
}

0 commit comments

Comments
 (0)