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 | 80 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/widget/app_launcher/init.lua b/widget/app_launcher/init.lua index 6aef106a..9dbd0ec3 100644 --- a/widget/app_launcher/init.lua +++ b/widget/app_launcher/init.lua @@ -330,15 +330,21 @@ local function search(self, text) end end -local function page_backward(self, direction) - if self._private.current_page > 1 then - self._private.current_page = self._private.current_page - 1 +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 = self._private.pages_count + 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 - local rows, columns = self._private.grid:get_dimension() unselect_app(self) - select_app(self, math.min(rows, #self._private.grid.children % self.apps_per_row), columns) + select_app(self, 1, 1) return else return @@ -349,9 +355,6 @@ local function page_backward(self, direction) -- Remove the current page apps from the grid self._private.grid:reset() - local max_app_index_to_include = self._private.apps_per_page * self._private.current_page - local min_app_index_to_include = max_app_index_to_include - self._private.apps_per_page - 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 @@ -359,39 +362,26 @@ local function page_backward(self, direction) end end - local rows, columns = self._private.grid:get_dimension() - if self._private.current_page < self._private.pages_count then - if direction == "up" then - select_app(self, rows, columns) - else - -- Keep the same row from last page - select_app(self, pos.row, columns) - end - elseif self.wrap_page_scrolling then - if direction == "up" then - select_app(self, math.min(rows, #self._private.grid.children % self.apps_per_row), columns) + if self._private.current_page > 1 or self.wrap_page_scrolling then + if direction == "down" then + select_app(self, 1, 1) else - -- Keep the same row from last page - select_app(self, math.min(pos.row, #self._private.grid.children % self.apps_per_row), columns) + 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_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 +local function page_backward(self, direction) + if self._private.current_page > 1 then + self._private.current_page = self._private.current_page - 1 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 + self._private.current_page = self._private.pages_count elseif self.wrap_app_scrolling then + local rows, columns = self._private.grid:get_dimension() unselect_app(self) - select_app(self, 1, 1) + select_app(self, math.min(rows, #self._private.grid.children % self.apps_per_row), columns) return else return @@ -402,6 +392,9 @@ local function page_forward(self, direction) -- Remove the current page apps from the grid self._private.grid:reset() + local max_app_index_to_include = self._private.apps_per_page * self._private.current_page + local min_app_index_to_include = max_app_index_to_include - self._private.apps_per_page + 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 @@ -409,13 +402,20 @@ local function page_forward(self, direction) end end - if self._private.current_page > 1 or self.wrap_page_scrolling then - if direction == "down" then - select_app(self, 1, 1) + local rows, columns = self._private.grid:get_dimension() + if self._private.current_page < self._private.pages_count then + if direction == "up" then + select_app(self, rows, columns) else - local rows, _ = self._private.grid:get_dimension() - local row = math.min(pos.row, rows) - select_app(self, row, 1) + -- Keep the same row from last page + select_app(self, pos.row, columns) + end + elseif self.wrap_page_scrolling then + if direction == "up" then + select_app(self, math.min(rows, #self._private.grid.children % self.apps_per_row), columns) + else + -- Keep the same row from last page + select_app(self, math.min(pos.row, #self._private.grid.children % self.apps_per_row), columns) end end end