mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-14 14:23:47 -05:00
Add change-nth action
Example: # Start with --nth 1, then 2, then 3, then back to the default, 1 echo 'foo foobar foobarbaz' | fzf --bind 'space:change-nth(2|3|)' --nth 1 -q foo Close #4172 Close #3109
This commit is contained in:
@@ -299,6 +299,7 @@ type Terminal struct {
|
||||
scrollbar string
|
||||
previewScrollbar string
|
||||
ansi bool
|
||||
nth []Range
|
||||
tabstop int
|
||||
margin [4]sizeSpec
|
||||
padding [4]sizeSpec
|
||||
@@ -462,6 +463,7 @@ const (
|
||||
actChangePreviewLabel
|
||||
actChangePrompt
|
||||
actChangeQuery
|
||||
actChangeNth
|
||||
actClearScreen
|
||||
actClearQuery
|
||||
actClearSelection
|
||||
@@ -597,6 +599,7 @@ type placeholderFlags struct {
|
||||
type searchRequest struct {
|
||||
sort bool
|
||||
sync bool
|
||||
nth *[]Range
|
||||
command *commandSpec
|
||||
environ []string
|
||||
changed bool
|
||||
@@ -880,6 +883,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
||||
header: []string{},
|
||||
header0: opts.Header,
|
||||
ansi: opts.Ansi,
|
||||
nth: opts.Nth,
|
||||
tabstop: opts.Tabstop,
|
||||
hasStartActions: false,
|
||||
hasResultActions: false,
|
||||
@@ -4359,6 +4363,7 @@ func (t *Terminal) Loop() error {
|
||||
}
|
||||
for loopIndex := int64(0); looping; loopIndex++ {
|
||||
var newCommand *commandSpec
|
||||
var newNth *[]Range
|
||||
var reloadSync bool
|
||||
changed := false
|
||||
beof := false
|
||||
@@ -4618,6 +4623,22 @@ func (t *Terminal) Loop() error {
|
||||
}
|
||||
t.multi = multi
|
||||
req(reqList, reqInfo)
|
||||
case actChangeNth:
|
||||
changed = true
|
||||
|
||||
// Split nth expression
|
||||
tokens := strings.Split(a.a, "|")
|
||||
if nth, err := splitNth(tokens[0]); err == nil {
|
||||
// Changed
|
||||
newNth = &nth
|
||||
} else {
|
||||
// The default
|
||||
newNth = &t.nth
|
||||
}
|
||||
// Cycle
|
||||
if len(tokens) > 1 {
|
||||
a.a = strings.Join(append(tokens[1:], tokens[0]), "|")
|
||||
}
|
||||
case actChangeQuery:
|
||||
t.input = []rune(a.a)
|
||||
t.cx = len(t.input)
|
||||
@@ -5537,7 +5558,7 @@ func (t *Terminal) Loop() error {
|
||||
reload := changed || newCommand != nil
|
||||
var reloadRequest *searchRequest
|
||||
if reload {
|
||||
reloadRequest = &searchRequest{sort: t.sort, sync: reloadSync, command: newCommand, environ: t.environ(), changed: changed}
|
||||
reloadRequest = &searchRequest{sort: t.sort, sync: reloadSync, nth: newNth, command: newCommand, environ: t.environ(), changed: changed}
|
||||
}
|
||||
t.mutex.Unlock() // Must be unlocked before touching reqBox
|
||||
|
||||
|
||||
Reference in New Issue
Block a user