1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Use model searching in commits (and sub-commits) view

This commit is contained in:
Stefan Haller
2024-05-31 17:24:50 +02:00
parent 779e6f95a3
commit 6a6316cfb6
75 changed files with 9066 additions and 4175 deletions

View File

@ -2,12 +2,14 @@ package helpers
import (
"fmt"
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
)
// NOTE: this helper supports both filtering and searching. Filtering is when
@ -156,17 +158,26 @@ func (self *SearchHelper) ConfirmSearch() error {
context.GetSearchHistory().Push(searchString)
}
view := context.GetView()
if err := self.c.PopContext(); err != nil {
return err
}
if err := view.Search(searchString); err != nil {
return err
return context.GetView().Search(searchString, modelSearchResults(context))
}
func modelSearchResults(context types.ISearchableContext) []gocui.SearchPosition {
searchString := context.GetSearchString()
var normalizedSearchStr string
// if we have any uppercase characters we'll do a case-sensitive search
caseSensitive := utils.ContainsUppercase(searchString)
if caseSensitive {
normalizedSearchStr = searchString
} else {
normalizedSearchStr = strings.ToLower(searchString)
}
return nil
return context.ModelSearchResults(normalizedSearchStr, caseSensitive)
}
func (self *SearchHelper) CancelPrompt() error {
@ -239,6 +250,25 @@ func (self *SearchHelper) ReApplyFilter(context types.Context) {
}
}
func (self *SearchHelper) ReApplySearch(ctx types.Context) {
// Reapply the search if the model has changed. This is needed for contexts
// that use the model for searching, to pass the new model search positions
// to the view.
searchableContext, ok := ctx.(types.ISearchableContext)
if ok {
ctx.GetView().UpdateSearchResults(searchableContext.GetSearchString(), modelSearchResults(searchableContext))
state := self.searchState()
if ctx == state.Context {
// Re-render the "x of y" search status, unless the search prompt is
// open for typing.
if self.c.CurrentContext().GetKey() != context.SEARCH_CONTEXT_KEY {
self.RenderSearchStatus(searchableContext)
}
}
}
}
func (self *SearchHelper) RenderSearchStatus(c types.Context) {
if c.GetKey() == context.SEARCH_CONTEXT_KEY {
return