mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
This bundles the keyName and a rune, so that we don't have to pass these around separately everywhere. This should make it easier to swap out the rune for a string when we upgrade to tcell v3.
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package gui
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gocui"
|
|
)
|
|
|
|
func (gui *Gui) handleEditorKeypress(v *gocui.View, key gocui.Key, mod gocui.Modifier, allowMultiline bool) bool {
|
|
if key.KeyName() == gocui.KeyEnter && allowMultiline {
|
|
v.TextArea.TypeCharacter("\n")
|
|
v.RenderTextArea()
|
|
return true
|
|
}
|
|
|
|
return gocui.DefaultEditor.Edit(v, key, mod)
|
|
}
|
|
|
|
// 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, mod gocui.Modifier) bool {
|
|
matched := gui.handleEditorKeypress(v, key, mod, false)
|
|
v.RenderTextArea()
|
|
gui.c.Contexts().CommitMessage.RenderSubtitle()
|
|
return matched
|
|
}
|
|
|
|
func (gui *Gui) commitDescriptionEditor(v *gocui.View, key gocui.Key, mod gocui.Modifier) bool {
|
|
matched := gui.handleEditorKeypress(v, key, mod, true)
|
|
v.RenderTextArea()
|
|
return matched
|
|
}
|
|
|
|
func (gui *Gui) promptEditor(v *gocui.View, key gocui.Key, mod gocui.Modifier) bool {
|
|
matched := gui.handleEditorKeypress(v, key, mod, false)
|
|
|
|
v.RenderTextArea()
|
|
|
|
suggestionsContext := gui.State.Contexts.Suggestions
|
|
if suggestionsContext.State.FindSuggestions != nil {
|
|
input := v.TextArea.GetContent()
|
|
suggestionsContext.State.AsyncHandler.Do(func() func() {
|
|
suggestions := suggestionsContext.State.FindSuggestions(input)
|
|
return func() { suggestionsContext.SetSuggestions(suggestions) }
|
|
})
|
|
}
|
|
|
|
return matched
|
|
}
|
|
|
|
func (gui *Gui) searchEditor(v *gocui.View, key gocui.Key, mod gocui.Modifier) bool {
|
|
matched := gui.handleEditorKeypress(v, key, mod, false)
|
|
v.RenderTextArea()
|
|
|
|
searchString := v.TextArea.GetContent()
|
|
|
|
gui.helpers.Search.OnPromptContentChanged(searchString)
|
|
|
|
return matched
|
|
}
|