From 611e382ff9fdedd76fc6a3907d6c9efe40467f6e Mon Sep 17 00:00:00 2001 From: Ksaper Date: Sun, 5 Feb 2023 00:44:24 +0200 Subject: [PATCH] I like page_forward being before backward --- widget/app_launcher/init.lua | 86 ++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/widget/app_launcher/init.lua b/widget/app_launcher/init.lua index 6aef106..9dbd0ec 100644 --- a/widget/app_launcher/init.lua +++ b/widget/app_launcher/init.lua @@ -330,6 +330,49 @@ local function search(self, text) end end +local function page_forward(self, direction) + local min_app_index_to_include = 0 + local max_app_index_to_include = self._private.apps_per_page + + if self._private.current_page < self._private.pages_count then + min_app_index_to_include = self._private.apps_per_page * self._private.current_page + self._private.current_page = self._private.current_page + 1 + max_app_index_to_include = self._private.apps_per_page * self._private.current_page + elseif self.wrap_page_scrolling and #self._private.matched_entries >= self._private.max_apps_per_page then + self._private.current_page = 1 + min_app_index_to_include = 0 + max_app_index_to_include = self._private.apps_per_page + elseif self.wrap_app_scrolling then + unselect_app(self) + select_app(self, 1, 1) + return + else + return + end + + local pos = self._private.grid:get_widget_position(self._private.active_widget) + + -- Remove the current page apps from the grid + self._private.grid:reset() + + for index, entry in pairs(self._private.matched_entries) do + -- Only add widgets that are between this range (part of the current page) + if index > min_app_index_to_include and index <= max_app_index_to_include then + self._private.grid:add(create_app_widget(self, entry)) + end + end + + if self._private.current_page > 1 or self.wrap_page_scrolling then + if direction == "down" then + select_app(self, 1, 1) + else + local rows, _ = self._private.grid:get_dimension() + local row = math.min(pos.row, rows) + select_app(self, row, 1) + end + end +end + local function page_backward(self, direction) if self._private.current_page > 1 then self._private.current_page = self._private.current_page - 1 @@ -377,49 +420,6 @@ local function page_backward(self, direction) end end -local function page_forward(self, direction) - local min_app_index_to_include = 0 - local max_app_index_to_include = self._private.apps_per_page - - if self._private.current_page < self._private.pages_count then - min_app_index_to_include = self._private.apps_per_page * self._private.current_page - self._private.current_page = self._private.current_page + 1 - max_app_index_to_include = self._private.apps_per_page * self._private.current_page - elseif self.wrap_page_scrolling and #self._private.matched_entries >= self._private.max_apps_per_page then - self._private.current_page = 1 - min_app_index_to_include = 0 - max_app_index_to_include = self._private.apps_per_page - elseif self.wrap_app_scrolling then - unselect_app(self) - select_app(self, 1, 1) - return - else - return - end - - local pos = self._private.grid:get_widget_position(self._private.active_widget) - - -- Remove the current page apps from the grid - self._private.grid:reset() - - for index, entry in pairs(self._private.matched_entries) do - -- Only add widgets that are between this range (part of the current page) - if index > min_app_index_to_include and index <= max_app_index_to_include then - self._private.grid:add(create_app_widget(self, entry)) - end - end - - if self._private.current_page > 1 or self.wrap_page_scrolling then - if direction == "down" then - select_app(self, 1, 1) - else - local rows, _ = self._private.grid:get_dimension() - local row = math.min(pos.row, rows) - select_app(self, row, 1) - end - end -end - local function scroll_up(self) if #self._private.grid.children < 1 then self._private.active_widget = nil