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.
reviewable/pr6755/r1
georgeto 4 years ago committed by Frans de Jonge
parent b668791c9c
commit 0fa45c21cf

@ -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

Loading…
Cancel
Save