From 297ea259bb007b4f91ca750832d1057bd5bce177 Mon Sep 17 00:00:00 2001 From: Ksaper Date: Fri, 3 Mar 2023 14:32:23 +0200 Subject: [PATCH] Don't loop twice --- widget/app_launcher/init.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/widget/app_launcher/init.lua b/widget/app_launcher/init.lua index 745457e..8bf4ee1 100644 --- a/widget/app_launcher/init.lua +++ b/widget/app_launcher/init.lua @@ -461,6 +461,11 @@ function app_launcher:search() if text == "" then self._private.matched_apps = self._private.all_apps + for _, matched_app in ipairs(self._private.matched_apps) do + if #self:get_grid().children + 1 <= self._private.max_apps_per_page then + self:get_grid():add(app_widget:get(self, matched_app)) + end + end else local matched_apps = Gio.DesktopAppInfo.search(text:lower()) for _, matched_app in ipairs(matched_apps) do @@ -468,17 +473,15 @@ function app_launcher:search() for _, app in ipairs(self._private.all_apps) do if app.id == app_id then table.insert(self._private.matched_apps, app) + -- Only add the widgets for apps that are part of the first page + if #self:get_grid().children + 1 <= self._private.max_apps_per_page then + self:get_grid():add(app_widget:get(self, app)) + end end end end end end - for _, app in ipairs(self._private.matched_apps) do - -- Only add the widgets for apps that are part of the first page - if #self:get_grid().children + 1 <= self._private.max_apps_per_page then - self:get_grid():add(app_widget:get(self, app)) - end - end -- Recalculate the apps per page based on the current matched apps self._private.apps_per_page = math.min(#self._private.matched_apps, self._private.max_apps_per_page)