diff --git a/internal/ui/prompt.go b/internal/ui/prompt.go index fd4051956a..bcc7271035 100644 --- a/internal/ui/prompt.go +++ b/internal/ui/prompt.go @@ -122,6 +122,14 @@ func (p *Prompt) SendStrokes(s string) { } } +// Deactivate sets the prompt as inactive. +func (p *Prompt) Deactivate() { + if p.model != nil { + p.model.ClearText(true) + p.model.SetActive(false) + } +} + // SetModel sets the prompt buffer model. func (p *Prompt) SetModel(m PromptModel) { if p.model != nil { diff --git a/internal/ui/prompt_test.go b/internal/ui/prompt_test.go index bbe456a374..1348ca7301 100644 --- a/internal/ui/prompt_test.go +++ b/internal/ui/prompt_test.go @@ -51,6 +51,19 @@ func TestCmdMode(t *testing.T) { } } +func TestPrompt_Deactivate(t *testing.T) { + model := model.NewFishBuff(':', model.CommandBuffer) + v := ui.NewPrompt(&ui.App{}, true, config.NewStyles()) + v.SetModel(model) + model.AddListener(v) + + model.SetActive(true) + if assert.True(t, v.InCmdMode()) { + v.Deactivate() + assert.False(t, v.InCmdMode()) + } +} + // Tests that, when active, the prompt has the appropriate color func TestPromptColor(t *testing.T) { styles := config.NewStyles() diff --git a/internal/view/app.go b/internal/view/app.go index 214f349c65..7de20d7888 100644 --- a/internal/view/app.go +++ b/internal/view/app.go @@ -641,12 +641,11 @@ func (a *App) dirCmd(path string) error { } func (a *App) helpCmd(evt *tcell.EventKey) *tcell.EventKey { - top := a.Content.Top() - - if a.CmdBuff().InCmdMode() || (top != nil && top.InCmdMode()) { + if evt != nil && evt.Rune() == '?' && a.Prompt().InCmdMode() { return evt } + top := a.Content.Top() if top != nil && top.Name() == "help" { a.Content.Pop() return nil @@ -656,6 +655,7 @@ func (a *App) helpCmd(evt *tcell.EventKey) *tcell.EventKey { a.Flash().Err(err) } + a.Prompt().Deactivate() return nil }