Skip to content

Commit

Permalink
proper handling of help commands (fixes #2154) (#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjiec authored Nov 29, 2023
1 parent c639b6a commit 0c642c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions internal/ui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions internal/ui/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions internal/view/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -656,6 +655,7 @@ func (a *App) helpCmd(evt *tcell.EventKey) *tcell.EventKey {
a.Flash().Err(err)
}

a.Prompt().Deactivate()
return nil
}

Expand Down

0 comments on commit 0c642c6

Please sign in to comment.