proper handling of help commands (fixes #2154) (#2319)

mine
Jayson Wang 2023-11-29 23:56:27 +08:00 committed by GitHub
parent c639b6a5cf
commit 0c642c6786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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
}