Merge pull request #165 from jpirnay/fix-button-handler
fix: Eliminate button race condition in filebrowser
This commit is contained in:
@@ -164,19 +164,22 @@ void OpdsBookBrowserActivity::loop() {
|
||||
}
|
||||
|
||||
if (!entries.empty()) {
|
||||
buttonNavigator.onNextRelease([this] {
|
||||
// Navigator is restricted to Up/Down so a Left release used to launch
|
||||
// search (line above) cannot also be consumed here as a previous-item
|
||||
// step on the same tick.
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this] {
|
||||
selectorIndex = ButtonNavigator::nextIndex(selectorIndex, entries.size());
|
||||
requestUpdate();
|
||||
});
|
||||
buttonNavigator.onPreviousRelease([this] {
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this] {
|
||||
selectorIndex = ButtonNavigator::previousIndex(selectorIndex, entries.size());
|
||||
requestUpdate();
|
||||
});
|
||||
buttonNavigator.onNextContinuous([this] {
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this] {
|
||||
selectorIndex = ButtonNavigator::nextPageIndex(selectorIndex, entries.size(), PAGE_ITEMS);
|
||||
requestUpdate();
|
||||
});
|
||||
buttonNavigator.onPreviousContinuous([this] {
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this] {
|
||||
selectorIndex = ButtonNavigator::previousPageIndex(selectorIndex, entries.size(), PAGE_ITEMS);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
@@ -252,17 +252,19 @@ void GlobalBookmarksActivity::loop() {
|
||||
|
||||
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false);
|
||||
|
||||
buttonNavigator.onNextRelease([this] {
|
||||
// Navigator is restricted to Up/Down so the Left (rename) and Right (delete)
|
||||
// handlers above cannot race default cursor movement on the same release tick.
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this] {
|
||||
selectorIndex = buttonNavigator.nextIndex(selectorIndex);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onPreviousRelease([this] {
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this] {
|
||||
selectorIndex = buttonNavigator.previousIndex(selectorIndex);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onNextContinuous([this, total, pageItems] {
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this, total, pageItems] {
|
||||
int next = ButtonNavigator::nextPageIndex(selectorIndex, total, pageItems);
|
||||
if (isSeparatorRow(next)) {
|
||||
const int adj = ButtonNavigator::nextIndex(next, total, [this](int i) { return !isSeparatorRow(i); });
|
||||
@@ -272,7 +274,7 @@ void GlobalBookmarksActivity::loop() {
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onPreviousContinuous([this, total, pageItems] {
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this, total, pageItems] {
|
||||
int prev = ButtonNavigator::previousPageIndex(selectorIndex, total, pageItems);
|
||||
if (isSeparatorRow(prev)) {
|
||||
const int adj = ButtonNavigator::previousIndex(prev, total, [this](int i) { return !isSeparatorRow(i); });
|
||||
|
||||
@@ -125,22 +125,26 @@ void RecentBooksActivity::loop() {
|
||||
|
||||
int listSize = static_cast<int>(recentBooks.size());
|
||||
|
||||
buttonNavigator.onNextRelease([this, listSize] {
|
||||
// Navigator is restricted to Up/Down so it cannot race the Left/Right Short
|
||||
// handlers above: with a double-click action configured, Short events are
|
||||
// deferred 300ms while wasReleased() is immediate, which would otherwise let
|
||||
// the cursor move before the custom action runs on the wrong entry.
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this, listSize] {
|
||||
selectorIndex = ButtonNavigator::nextIndex(static_cast<int>(selectorIndex), listSize);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onPreviousRelease([this, listSize] {
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this, listSize] {
|
||||
selectorIndex = ButtonNavigator::previousIndex(static_cast<int>(selectorIndex), listSize);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onNextContinuous([this, listSize, pageItems] {
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this, listSize, pageItems] {
|
||||
selectorIndex = ButtonNavigator::nextPageIndex(static_cast<int>(selectorIndex), listSize, pageItems);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onPreviousContinuous([this, listSize, pageItems] {
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this, listSize, pageItems] {
|
||||
selectorIndex = ButtonNavigator::previousPageIndex(static_cast<int>(selectorIndex), listSize, pageItems);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user