From f02d8e4ce7ce9f58626f1ce29023c80e5e33d6fa Mon Sep 17 00:00:00 2001 From: Chev Date: Mon, 6 Jan 2025 15:34:22 -0800 Subject: [PATCH] SprayMesh Extended: Fix search being broken --- .../lua/vgui/dsprayconfiguration.lua | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua b/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua index 1383f50..5993d78 100644 --- a/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua +++ b/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua @@ -497,24 +497,34 @@ function PANEL:AddSpray(url, name) end function PANEL:FilterSearch(text) + local numVisible = 0 + + local queryIsEmpty = string.Trim(text, " ") == "" + for url, sprayPanel in pairs(self.Sprays) do if not IsValid(sprayPanel) then continue end - -- Since spray panels are wrapped inside a parent, we want to target visibility for the parent instead - local panelParent = sprayPanel:GetParent() - - local queryIsEmpty = string.Trim(text, " ") == "" local textInURL = string.find(url:lower(), text:lower(), 0, true) ~= nil local textInName = string.find(sprayPanel.Name:lower(), text:lower(), 0, true) ~= nil if queryIsEmpty or textInURL or textInName then - panelParent:SetVisible(true) + sprayPanel:SetVisible(true) + numVisible = numVisible + 1 else - panelParent:SetVisible(false) + sprayPanel:SetVisible(false) end end self.IconLayout:Layout() + self.Scroll.VBar:SetScroll(0) + + -- Give self.IconLayout some time (the next frame) to relayout + -- Then, we can re-layout the scroll bar + timer.Simple(0, function() + if IsValid(self.Scroll) then + self.Scroll:Rebuild() + end + end) end -- Register control