mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
better search logic
This commit is contained in:
parent
702361559f
commit
e6d4a97545
10 changed files with 13 additions and 32 deletions
|
|
@ -71,10 +71,6 @@ func (gui *Gui) getContainersPanel() *SideListPanel[*commands.Container] {
|
|||
},
|
||||
}
|
||||
},
|
||||
getSearchStrings: func(container *commands.Container) []string {
|
||||
// TODO: think about more things to search on
|
||||
return []string{container.Name}
|
||||
},
|
||||
getContextCacheKey: func(container *commands.Container) string {
|
||||
return container.ID + "-" + container.Container.State
|
||||
},
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ type guiState struct {
|
|||
}
|
||||
|
||||
type searchingState struct {
|
||||
view *gocui.View
|
||||
panel ISideListPanel
|
||||
isSearching bool
|
||||
searchString string
|
||||
|
|
|
|||
|
|
@ -37,9 +37,6 @@ func (gui *Gui) getImagesPanel() *SideListPanel[*commands.Image] {
|
|||
},
|
||||
}
|
||||
},
|
||||
getSearchStrings: func(image *commands.Image) []string {
|
||||
return []string{image.Name, image.Tag}
|
||||
},
|
||||
getContextCacheKey: func(image *commands.Image) string {
|
||||
return image.ID
|
||||
},
|
||||
|
|
@ -113,7 +110,7 @@ func (gui *Gui) refreshStateImages() error {
|
|||
}
|
||||
|
||||
func (gui *Gui) filterString(view *gocui.View) string {
|
||||
if gui.State.Searching.view != view {
|
||||
if gui.State.Searching.panel != nil && gui.State.Searching.panel.View() != view {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,9 +63,6 @@ type SideListPanel[T comparable] struct {
|
|||
|
||||
gui IGui
|
||||
|
||||
// returns strings that can be filtered on
|
||||
getSearchStrings func(item T) []string
|
||||
|
||||
// this filter is applied on top of additional default filters
|
||||
filter func(T) bool
|
||||
sort func(a, b T) bool
|
||||
|
|
@ -244,7 +241,7 @@ func (self *SideListPanel[T]) FilterAndSort() {
|
|||
}
|
||||
|
||||
if lo.SomeBy(self.gui.IgnoreStrings(), func(ignore string) bool {
|
||||
return lo.SomeBy(self.getSearchStrings(item), func(searchString string) bool {
|
||||
return lo.SomeBy(self.getDisplayStrings(item), func(searchString string) bool {
|
||||
return strings.Contains(searchString, ignore)
|
||||
})
|
||||
}) {
|
||||
|
|
@ -252,7 +249,7 @@ func (self *SideListPanel[T]) FilterAndSort() {
|
|||
}
|
||||
|
||||
if filterString != "" {
|
||||
return lo.SomeBy(self.getSearchStrings(item), func(searchString string) bool {
|
||||
return lo.SomeBy(self.getDisplayStrings(item), func(searchString string) bool {
|
||||
return strings.Contains(searchString, filterString)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,8 @@ func (gui *Gui) getMenuPanel() *SideListPanel[*MenuItem] {
|
|||
},
|
||||
noItemsMessage: "",
|
||||
gui: gui.intoInterface(),
|
||||
getSearchStrings: func(menuItem *MenuItem) []string {
|
||||
return menuItem.LabelColumns
|
||||
},
|
||||
onClick: gui.onMenuPress,
|
||||
sort: nil,
|
||||
onClick: gui.onMenuPress,
|
||||
sort: nil,
|
||||
getDisplayStrings: func(menuItem *MenuItem) []string {
|
||||
return menuItem.LabelColumns
|
||||
},
|
||||
|
|
|
|||
|
|
@ -54,9 +54,6 @@ func (gui *Gui) getProjectPanel() *SideListPanel[*commands.Project] {
|
|||
},
|
||||
}
|
||||
},
|
||||
getSearchStrings: func(project *commands.Project) []string {
|
||||
return []string{project.Name}
|
||||
},
|
||||
getContextCacheKey: func(project *commands.Project) string {
|
||||
return project.Name
|
||||
},
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ func (gui *Gui) handleOpenSearch() error {
|
|||
}
|
||||
|
||||
gui.State.Searching.isSearching = true
|
||||
gui.State.Searching.view = panel.View()
|
||||
gui.State.Searching.panel = panel
|
||||
|
||||
return gui.switchFocus(gui.Views.Search)
|
||||
|
|
@ -20,6 +19,7 @@ func (gui *Gui) handleOpenSearch() error {
|
|||
func (gui *Gui) onNewSearchString(value string) error {
|
||||
// need to refresh the right list panel.
|
||||
gui.State.Searching.searchString = value
|
||||
gui.ResetOrigin(gui.State.Searching.panel.View())
|
||||
return gui.State.Searching.panel.RerenderList()
|
||||
}
|
||||
|
||||
|
|
@ -45,11 +45,12 @@ func (gui *Gui) escapeSearchPrompt() error {
|
|||
func (gui *Gui) clearSearch() error {
|
||||
gui.State.Searching.searchString = ""
|
||||
gui.State.Searching.isSearching = false
|
||||
gui.State.Searching.view = nil
|
||||
panel := gui.State.Searching.panel
|
||||
gui.State.Searching.panel = nil
|
||||
gui.Views.Search.ClearTextArea()
|
||||
|
||||
gui.ResetOrigin(panel.View())
|
||||
|
||||
return panel.RerenderList()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,10 +52,6 @@ func (gui *Gui) getServicesPanel() *SideListPanel[*commands.Service] {
|
|||
},
|
||||
}
|
||||
},
|
||||
getSearchStrings: func(service *commands.Service) []string {
|
||||
// TODO: think about more things to search on
|
||||
return []string{service.Name}
|
||||
},
|
||||
getContextCacheKey: func(service *commands.Service) string {
|
||||
if service.Container == nil {
|
||||
return service.ID
|
||||
|
|
|
|||
|
|
@ -230,6 +230,11 @@ func (gui *Gui) FocusY(selectedY int, lineCount int, v *gocui.View) {
|
|||
gui.focusY(selectedY, lineCount, v)
|
||||
}
|
||||
|
||||
func (gui *Gui) ResetOrigin(v *gocui.View) {
|
||||
_ = v.SetOrigin(0, 0)
|
||||
_ = v.SetCursor(0, 0)
|
||||
}
|
||||
|
||||
func (gui *Gui) cleanString(s string) string {
|
||||
output := string(bom.Clean([]byte(s)))
|
||||
return utils.NormalizeLinefeeds(output)
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ func (gui *Gui) getVolumesPanel() *SideListPanel[*commands.Volume] {
|
|||
},
|
||||
}
|
||||
},
|
||||
getSearchStrings: func(volume *commands.Volume) []string {
|
||||
// TODO: think about more things to search on
|
||||
return []string{volume.Name}
|
||||
},
|
||||
getContextCacheKey: func(volume *commands.Volume) string {
|
||||
return volume.Name
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue