Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
I like page_forward being before backward
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper24 committed Feb 4, 2023
1 parent 0790382 commit 611e382
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions widget/app_launcher/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -349,49 +355,33 @@ 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
self._private.grid:add(create_app_widget(self, entry))
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
Expand All @@ -402,20 +392,30 @@ 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
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)
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
Expand Down

0 comments on commit 611e382

Please sign in to comment.