mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
The filter input is where the keyboard points for as long as such a menu is open, so that the first printable key can go straight into it. The menu still gets every key the input doesn't take, because the input view is embedded in the menu view, and the two are drawn as one focused panel. Which keys the input takes changes once there is a filter: until then printable keys still drive the menu, so that the configured navigation keys work as usual, and afterwards they are all filter text. A menu item's own keys are never bound in such a menu, because typing one has to reach the filter rather than execute the item. Escape gives up the filter and leaves the menu open; the next one closes it. The filter prompt behind '/' is gone from these menus: the row already does that job, and a second filter would only be confusing. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
package gui
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gocui"
|
|
)
|
|
|
|
func (gui *Gui) handleEditorKeypress(v *gocui.View, key gocui.Key, allowMultiline bool) bool {
|
|
if key.Equals(gocui.NewKeyName(gocui.KeyEnter)) && allowMultiline {
|
|
v.TextArea.TypeCharacter("\n")
|
|
v.RenderTextArea()
|
|
return true
|
|
}
|
|
|
|
return gocui.DefaultEditor.Edit(v, key)
|
|
}
|
|
|
|
// we've just copy+pasted the editor from gocui to here so that we can also re-
|
|
// render the commit message length on each keypress
|
|
func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key) bool {
|
|
matched := gui.handleEditorKeypress(v, key, false)
|
|
v.RenderTextArea()
|
|
gui.c.Contexts().CommitMessage.RenderSubtitle()
|
|
return matched
|
|
}
|
|
|
|
func (gui *Gui) commitDescriptionEditor(v *gocui.View, key gocui.Key) bool {
|
|
matched := gui.handleEditorKeypress(v, key, true)
|
|
v.RenderTextArea()
|
|
return matched
|
|
}
|
|
|
|
func (gui *Gui) promptEditor(v *gocui.View, key gocui.Key) bool {
|
|
matched := gui.handleEditorKeypress(v, key, false)
|
|
|
|
v.RenderTextArea()
|
|
|
|
suggestionsContext := gui.State.Contexts.Suggestions
|
|
// Capture the suggestions function and the input here, on the UI thread; the
|
|
// main thread rewrites State.FindSuggestions when it (re)creates a prompt
|
|
// panel, so reading it from the worker below would race that write.
|
|
if findSuggestions := suggestionsContext.State.FindSuggestions; findSuggestions != nil {
|
|
input := v.TextArea.GetContent()
|
|
suggestionsContext.State.AsyncHandler.Do(func() func() {
|
|
suggestions := findSuggestions(input)
|
|
return func() { suggestionsContext.SetSuggestions(suggestions) }
|
|
})
|
|
}
|
|
|
|
return matched
|
|
}
|
|
|
|
func (gui *Gui) menuFilterEditor(v *gocui.View, key gocui.Key) bool {
|
|
contentBefore := v.TextArea.GetContent()
|
|
|
|
matched := gui.handleEditorKeypress(v, key, false)
|
|
if !matched {
|
|
// Give the global keybindings a chance at the key, e.g. so that ctrl-c
|
|
// still quits while a menu is open.
|
|
return false
|
|
}
|
|
|
|
v.RenderTextArea()
|
|
|
|
content := v.TextArea.GetContent()
|
|
if content == contentBefore {
|
|
// The key just moved the cursor around within the filter; refiltering would
|
|
// throw away the menu's selection for nothing.
|
|
return true
|
|
}
|
|
|
|
menuContext := gui.State.Contexts.Menu
|
|
menuContext.SetFilterStarted(true)
|
|
gui.helpers.Search.ApplyFilter(menuContext, content)
|
|
|
|
return true
|
|
}
|
|
|
|
func (gui *Gui) searchEditor(v *gocui.View, key gocui.Key) bool {
|
|
matched := gui.handleEditorKeypress(v, key, false)
|
|
v.RenderTextArea()
|
|
|
|
searchString := v.TextArea.GetContent()
|
|
|
|
gui.helpers.Search.OnPromptContentChanged(searchString)
|
|
|
|
return matched
|
|
}
|