From e47dc758c90fc151ef86dc5f189fdea19383d962 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 7 Jan 2024 15:43:17 +0900 Subject: [PATCH] Fix focus event not triggered in certain cases --- src/terminal.go | 13 ++++++++----- test/test_go.rb | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 152475f..295886d 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 1c1133d..aa4dfd4 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 }