mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
SortWidget: Fix moving of items over several positions
Previously items weren't actually moved, but swapped with the item at their new position. That works well if you move an item for one position. However, if you move an item over several positions, you won't get the expected behaivor.
This commit is contained in:
@@ -416,8 +416,9 @@ end
|
||||
function SortWidget:moveItem(diff)
|
||||
local move_to = self.marked + diff
|
||||
if move_to > 0 and move_to <= #self.item_table then
|
||||
table.insert(self.item_table, move_to, table.remove(self.item_table, self.marked))
|
||||
self.show_page = math.ceil(move_to/self.items_per_page)
|
||||
self:swapItems(self.marked, move_to)
|
||||
self.marked = move_to
|
||||
self:_populateItems()
|
||||
end
|
||||
end
|
||||
@@ -475,15 +476,6 @@ function SortWidget:_populateItems()
|
||||
end)
|
||||
end
|
||||
|
||||
function SortWidget:swapItems(pos1, pos2)
|
||||
if pos1 > 0 or pos2 <= #self.item_table then
|
||||
local entry = self.item_table[pos1]
|
||||
self.marked = pos2
|
||||
self.item_table[pos1] = self.item_table[pos2]
|
||||
self.item_table[pos2] = entry
|
||||
end
|
||||
end
|
||||
|
||||
function SortWidget:onAnyKeyPressed()
|
||||
return self:onClose()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user