[SortWidget] NT: add new keyEvents to widget#13154
Conversation
|
|
||
| function SortWidget:moveItem(diff) | ||
| function SortWidget:onMoveItem(diff) | ||
| if self.marked == 0 then return end -- don't crash when called with key events on NT |
There was a problem hiding this comment.
I played around with it a bit and I thought something like this might be nicer. It gets rid of the somewhat awkward touch-like approach and simply moves things around based on current focus.
diff --git a/frontend/ui/widget/sortwidget.lua b/frontend/ui/widget/sortwidget.lua
index f4b4c6edf..5535b100e 100644
--- a/frontend/ui/widget/sortwidget.lua
+++ b/frontend/ui/widget/sortwidget.lua
@@ -353,13 +353,13 @@ function SortWidget:registerKeyEvents()
self.key_events.PrevPage = { { Device.input.group.PgBack } }
self.key_events.ShowWidgetMenu = { { "Menu" } }
if Device:hasScreenKB() then
- self.key_events.MoveUp = { { "ScreenKB", "Up" }, event = "MoveItem", args = -1 }
- self.key_events.MoveDown = { { "ScreenKB", "Down" }, event = "MoveItem", args = 1 }
+ self.key_events.MoveUp = { { "ScreenKB", "Up" }, event = "MoveItemKB", args = -1 }
+ self.key_events.MoveDown = { { "ScreenKB", "Down" }, event = "MoveItemKB", args = 1 }
self.key_events.FirstPage = { { "ScreenKB", Device.input.group.PgBack }, event = "GoToPage", args = 1 }
self.key_events.LastPage = { { "ScreenKB", Device.input.group.PgFwd }, event = "GoToPage", args = self.pages }
elseif Device:hasKeyboard() then
- self.key_events.MoveUp = { { "Shift", "Up" }, event = "MoveItem", args = -1 }
- self.key_events.MoveDown = { { "Shift", "Down" }, event = "MoveItem", args = 1 }
+ self.key_events.MoveUp = { { "Shift", "Up" }, event = "MoveItemKB", args = -1 }
+ self.key_events.MoveDown = { { "Shift", "Down" }, event = "MoveItemKB", args = 1 }
self.key_events.FirstPage = { { "Shift", Device.input.group.PgBack }, event = "GoToPage", args = 1 }
self.key_events.LastPage = { { "Shift", Device.input.group.PgFwd }, event = "GoToPage", args = self.pages }
end
@@ -394,7 +394,6 @@ function SortWidget:onGoToPage(page)
end
function SortWidget:onMoveItem(diff)
- if self.marked == 0 then return end -- don't crash when called with key events on NT
local move_to = self.marked + diff
if move_to > 0 and move_to <= #self.item_table then
-- Remember the original state to support Cancel
@@ -408,6 +407,12 @@ function SortWidget:onMoveItem(diff)
end
end
+function SortWidget:onMoveItemKB(diff)
+ -- set self.marked to the item with focus
+ self.marked = self.selected.y + (self.show_page - 1) * self.items_per_page
+ self:onMoveItem(diff)
+end
+
-- make sure self.item_margin and self.item_height are set before calling this
function SortWidget:_populateItems()
self.main_content:clear()
@@ -440,11 +445,8 @@ function SortWidget:_populateItems()
-- Reset the focus to the top of the page when we're not moving an item (#12342)
self:moveFocusTo(1, 1)
else
- -- When we're moving an item, move the focus to the footer (last row),
- -- while keeping the focus on the current button (or cancel for the initial move,
- -- as there's only one column of items, so x == 1, which points to the first button, which is cancel).
- -- even when we change pages and the amount of rows may have changed
- self:moveFocusTo(self.selected.x, #self.layout)
+ -- Move focus to the moved item.
+ self:moveFocusTo(1, self.marked - idx_offset)
end
-- NOTE: We forgo our usual "Page x of y" wording because of space constraints given the way the widget is currently built
Frenzie
left a comment
There was a problem hiding this comment.
but when I look at the unified changes on GH it seems to ignore part of the second commit O.o
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Commodore64user)
|
Edit: never mind, I was confused by onGoToPage, is all. It's past midnight. :-) |
|
Something about this may not be quite right, or in any case trying to switch pages seems to crash. |
|
I am not getting any crashes, I'm assuming you mean page turns inside the widget, which they are fine on my end. |
|
The good (?) news is that it was already an issue, but only in arrange statusbar items. That explains why I didn't notice it previously wrt this PR since I tested it (even if only summarily) on favorites or collections. |
|
I still don't understand what the problem is... i had tested it with multiple pages (when i over engineered the separator thing, i had like 4 pages worth of them) and it worked fine. No crashes. I actually think the self.pages ones isn't working, but unsure why since it also worked before. Going through the "arrange items" thing, made me realise that we should also have shortcuts for back and select when something is selected, but that is another matter. |
|
See #13186 it's probably not related to SortWidget at all. |
what's new
just a few QoL changes to the
SortWidgetclass for non-touch usersgoToPagetoonGoToPageand updated all references to this method.registerKeyEventsto handle the registration of key events.initto the newregisterKeyEventsmethod.onMoveItemKBmethod to handle item movement via keyboard events, ensuring themarkeditem is updated correctly._populateItemsto ensure the focus moves to the correct item after an item move operation.This change is