mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-18 11:05:16 +00:00
Limit the maximum number of focus events to process at once
This commit is contained in:
parent
091b7eacba
commit
8977c9257a
@ -55,6 +55,9 @@ var actionTypeRegex *regexp.Regexp
|
|||||||
|
|
||||||
const clearCode string = "\x1b[2J"
|
const clearCode string = "\x1b[2J"
|
||||||
|
|
||||||
|
// Number of maximum focus events to process synchronously
|
||||||
|
const maxFocusEvents = 10000
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{fzf:(?:query|action|prompt)}|{\+?f?nf?})`)
|
placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{fzf:(?:query|action|prompt)}|{\+?f?nf?})`)
|
||||||
whiteSuffix = regexp.MustCompile(`\s*$`)
|
whiteSuffix = regexp.MustCompile(`\s*$`)
|
||||||
@ -3305,6 +3308,7 @@ func (t *Terminal) Loop() {
|
|||||||
var doAction func(*action) bool
|
var doAction func(*action) bool
|
||||||
var doActions func(actions []*action) bool
|
var doActions func(actions []*action) bool
|
||||||
doActions = func(actions []*action) bool {
|
doActions = func(actions []*action) bool {
|
||||||
|
for iter := 0; iter <= maxFocusEvents; iter++ {
|
||||||
currentIndex := t.currentIndex()
|
currentIndex := t.currentIndex()
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
if !doAction(action) {
|
if !doAction(action) {
|
||||||
@ -3312,12 +3316,15 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if onFocus, prs := t.keymap[tui.Focus.AsEvent()]; prs {
|
if onFocus, prs := t.keymap[tui.Focus.AsEvent()]; prs && iter < maxFocusEvents {
|
||||||
if newIndex := t.currentIndex(); newIndex != currentIndex {
|
if newIndex := t.currentIndex(); newIndex != currentIndex {
|
||||||
t.lastFocus = newIndex
|
t.lastFocus = newIndex
|
||||||
return doActions(onFocus)
|
actions = onFocus
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
doAction = func(a *action) bool {
|
doAction = func(a *action) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user