diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2024-03-14 11:18:47 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-03-14 11:18:47 +0900 |
commit | 8977c9257a8093a82a2cffa4f7e6974e43206ef4 (patch) | |
tree | e5e0c63fb7e88ea61d145ca68cb344691b534f64 | |
parent | 091b7eacba6426a2027105ee8a76c356e3cc324b (diff) |
Limit the maximum number of focus events to process at oncedevel
-rw-r--r-- | src/terminal.go | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/terminal.go b/src/terminal.go index b8358891..b24950e8 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -55,6 +55,9 @@ var actionTypeRegex *regexp.Regexp const clearCode string = "\x1b[2J" +// Number of maximum focus events to process synchronously +const maxFocusEvents = 10000 + func init() { placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{fzf:(?:query|action|prompt)}|{\+?f?nf?})`) whiteSuffix = regexp.MustCompile(`\s*$`) @@ -3305,18 +3308,22 @@ func (t *Terminal) Loop() { var doAction func(*action) bool var doActions func(actions []*action) bool doActions = func(actions []*action) bool { - currentIndex := t.currentIndex() - for _, action := range actions { - if !doAction(action) { - return false + for iter := 0; iter <= maxFocusEvents; iter++ { + currentIndex := t.currentIndex() + for _, action := range actions { + if !doAction(action) { + return false + } } - } - if onFocus, prs := t.keymap[tui.Focus.AsEvent()]; prs { - if newIndex := t.currentIndex(); newIndex != currentIndex { - t.lastFocus = newIndex - return doActions(onFocus) + if onFocus, prs := t.keymap[tui.Focus.AsEvent()]; prs && iter < maxFocusEvents { + if newIndex := t.currentIndex(); newIndex != currentIndex { + t.lastFocus = newIndex + actions = onFocus + continue + } } + break } return true } |