summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-01-07 15:43:17 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-01-07 15:43:17 +0900
commite47dc758c90fc151ef86dc5f189fdea19383d962 (patch)
treee21c0015fca7282a11bdd960c21c64180b29950e
parentb92a843c5f2c13e0ca5b88ba4f0331e251649123 (diff)
Fix focus event not triggered in certain cases
-rw-r--r--src/terminal.go13
-rwxr-xr-xtest/test_go.rb4
2 files changed, 12 insertions, 5 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 152475f8..295886dd 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -251,6 +251,7 @@ type Terminal struct {
borderWidth int
count int
progress int
+ hasFocusActions bool
hasLoadActions bool
triggerLoad bool
reading bool
@@ -730,6 +731,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
ellipsis: opts.Ellipsis,
ansi: opts.Ansi,
tabstop: opts.Tabstop,
+ hasFocusActions: false,
hasLoadActions: false,
triggerLoad: false,
reading: true,
@@ -757,7 +759,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
killChan: make(chan int),
serverInputChan: make(chan []*action, 10),
serverOutputChan: make(chan string),
- eventChan: make(chan tui.Event, 3), // load / zero|one | GetChar
+ eventChan: make(chan tui.Event, 4), // (load + zero|one) | (focus) | (GetChar)
tui: renderer,
initFunc: func() { renderer.Init() },
executing: util.NewAtomicBool(false),
@@ -801,6 +803,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
}
}
+ _, t.hasFocusActions = t.keymap[tui.Focus.AsEvent()]
_, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]
if t.listenAddr != nil {
@@ -3070,9 +3073,9 @@ func (t *Terminal) Loop() {
t.track = trackDisabled
t.printInfo()
}
- if onFocus, prs := t.keymap[tui.Focus.AsEvent()]; prs && focusChanged && currentIndex != t.lastFocus {
- t.lastFocus = focusedIndex
- t.serverInputChan <- onFocus
+ if t.hasFocusActions && focusChanged && currentIndex != t.lastFocus {
+ t.lastFocus = currentIndex
+ t.eventChan <- tui.Focus.AsEvent()
}
if focusChanged || version != t.version {
version = t.version
@@ -3186,7 +3189,7 @@ func (t *Terminal) Loop() {
}
select {
case event = <-t.eventChan:
- needBarrier = !event.Is(tui.Load, tui.One, tui.Zero)
+ needBarrier = !event.Is(tui.Load, tui.Focus, tui.One, tui.Zero)
case serverActions := <-t.serverInputChan:
event = tui.Invalid.AsEvent()
if t.listenAddr == nil || t.listenAddr.IsLocal() || t.listenUnsafe {
diff --git a/test/test_go.rb b/test/test_go.rb
index 1c1133df..aa4dfd41 100755
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -2711,6 +2711,10 @@ class TestGoFZF < TestBase
tmux.until { |lines| assert_includes(lines[-1], '[[2]]') }
tmux.send_keys :X
tmux.until { |lines| assert_includes(lines[-1], '[[]]') }
+ tmux.send_keys :BSpace
+ tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }
+ tmux.send_keys :X
+ tmux.until { |lines| assert_includes(lines[-1], '[[]]') }
tmux.send_keys '?'
tmux.send_keys :BSpace
tmux.until { |lines| assert_equal 100, lines.match_count }