mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-10 11:10:18 +02:00
support labels for suggestions which are distinct from values
This commit is contained in:
parent
5671ec5f58
commit
be404068ff
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
@ -206,7 +207,7 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, s
|
|||||||
suggestionsView.Wrap = true
|
suggestionsView.Wrap = true
|
||||||
suggestionsView.FgColor = theme.GocuiDefaultTextColor
|
suggestionsView.FgColor = theme.GocuiDefaultTextColor
|
||||||
}
|
}
|
||||||
gui.setSuggestions([]string{})
|
gui.setSuggestions([]*types.Suggestion{})
|
||||||
_, _ = gui.g.SetViewOnTop("suggestions")
|
_, _ = gui.g.SetViewOnTop("suggestions")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +280,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
onSuggestionConfirm := gui.wrappedPromptConfirmationFunction(opts.handlersManageFocus, opts.handleConfirmPrompt, func() string { return gui.getSelectedSuggestion() })
|
onSuggestionConfirm := gui.wrappedPromptConfirmationFunction(opts.handlersManageFocus, opts.handleConfirmPrompt, func() string { return gui.getSelectedSuggestionValue() })
|
||||||
if err := gui.g.SetKeybinding("suggestions", nil, gui.getKey(keybindingConfig.Universal.Confirm), gocui.ModNone, onSuggestionConfirm); err != nil {
|
if err := gui.g.SetKeybinding("suggestions", nil, gui.getKey(keybindingConfig.Universal.Confirm), gocui.ModNone, onSuggestionConfirm); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package gui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -78,7 +80,16 @@ func (gui *Gui) editorWithCallback(v *gocui.View, key gocui.Key, ch rune, mod go
|
|||||||
input := v.Buffer()
|
input := v.Buffer()
|
||||||
branchNames := gui.getBranchNames()
|
branchNames := gui.getBranchNames()
|
||||||
|
|
||||||
suggestions := utils.FuzzySearch(input, branchNames)
|
matchingBranchNames := utils.FuzzySearch(input, branchNames)
|
||||||
|
|
||||||
|
suggestions := make([]*types.Suggestion, len(matchingBranchNames))
|
||||||
|
for i, branchName := range matchingBranchNames {
|
||||||
|
suggestions[i] = &types.Suggestion{
|
||||||
|
Value: branchName,
|
||||||
|
Label: utils.ColoredString(branchName, presentation.GetBranchColor(branchName)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gui.setSuggestions(suggestions)
|
gui.setSuggestions(suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
"github.com/jesseduffield/lazygit/pkg/tasks"
|
"github.com/jesseduffield/lazygit/pkg/tasks"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
@ -305,7 +306,7 @@ type guiState struct {
|
|||||||
StashEntries []*models.StashEntry
|
StashEntries []*models.StashEntry
|
||||||
CommitFiles []*models.CommitFile
|
CommitFiles []*models.CommitFile
|
||||||
// Suggestions will sometimes appear when typing into a prompt
|
// Suggestions will sometimes appear when typing into a prompt
|
||||||
Suggestions []string
|
Suggestions []*types.Suggestion
|
||||||
// FilteredReflogCommits are the ones that appear in the reflog panel.
|
// FilteredReflogCommits are the ones that appear in the reflog panel.
|
||||||
// when in filtering mode we only include the ones that match the given path
|
// when in filtering mode we only include the ones that match the given path
|
||||||
FilteredReflogCommits []*models.Commit
|
FilteredReflogCommits []*models.Commit
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package presentation
|
package presentation
|
||||||
|
|
||||||
func GetSuggestionListDisplayStrings(suggestions []string) [][]string {
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetSuggestionListDisplayStrings(suggestions []*types.Suggestion) [][]string {
|
||||||
lines := make([][]string, len(suggestions))
|
lines := make([][]string, len(suggestions))
|
||||||
|
|
||||||
for i := range suggestions {
|
for i := range suggestions {
|
||||||
@ -10,6 +14,6 @@ func GetSuggestionListDisplayStrings(suggestions []string) [][]string {
|
|||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSuggestionDisplayStrings(suggestion string) []string {
|
func getSuggestionDisplayStrings(suggestion *types.Suggestion) []string {
|
||||||
return []string{suggestion}
|
return []string{suggestion.Label}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,27 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
func (gui *Gui) getSelectedSuggestion() string {
|
import "github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
|
||||||
|
func (gui *Gui) getSelectedSuggestionValue() string {
|
||||||
|
selectedSuggestion := gui.getSelectedSuggestion()
|
||||||
|
|
||||||
|
if selectedSuggestion != nil {
|
||||||
|
return selectedSuggestion.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) getSelectedSuggestion() *types.Suggestion {
|
||||||
selectedLine := gui.State.Panels.Suggestions.SelectedLineIdx
|
selectedLine := gui.State.Panels.Suggestions.SelectedLineIdx
|
||||||
if selectedLine == -1 {
|
if selectedLine == -1 {
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.State.Suggestions[selectedLine]
|
return gui.State.Suggestions[selectedLine]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) setSuggestions(suggestions []string) {
|
func (gui *Gui) setSuggestions(suggestions []*types.Suggestion) {
|
||||||
view := gui.getSuggestionsView()
|
view := gui.getSuggestionsView()
|
||||||
if view == nil {
|
if view == nil {
|
||||||
return
|
return
|
||||||
|
8
pkg/gui/types/suggestion.go
Normal file
8
pkg/gui/types/suggestion.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Suggestion struct {
|
||||||
|
// value is the thing that we're matching on and the thing that will be submitted if you select the suggestion
|
||||||
|
Value string
|
||||||
|
// label is what is actually displayed so it can e.g. contain color
|
||||||
|
Label string
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user