Skip to content

[SortWidget] bug fix: Fix keyboard hold events targeting wrong item - #14252

Merged
Frenzie merged 4 commits into
koreader:masterfrom
Commodore64user:sortwidget
Sep 18, 2025
Merged

Frenzie merged 4 commits into
koreader:masterfrom
Commodore64user:sortwidget

Conversation

@Commodore64user

@Commodore64user Commodore64user commented Aug 30, 2025 •

Copy link
Copy Markdown
Member

bug fix

When using shift/screenkb + press on non-touch devices, hold events were always affecting the first item instead of the focused one. Added onHold() handler to SortWidget that directly targets the focused item, bypassing the coordinate-based gesture system that was causing the misdirection.

  • Renamed the onHold method to onHoldTouch in SortItemWidget, ensuring the method does not clash with FocusManager's own Hold events.
  • Updated the registerKeyEvents() method in SortWidget to add a new HoldNonTouch event for keyboard-based hold actions, and unified modifier handling for screen keyboard and physical keyboard inputs.
  • Added a new onHoldNonTouch method in SortWidget to handle keyboard-triggered hold events by invoking the onHoldTouch method on the currently focused item, enabling consistent hold behaviour for non-touch devices.

related issues


This change is Reviewable

@Commodore64user Commodore64user changed the title Fix keyboard hold events targeting wrong item in SortWidget [SortWidget] bug fix: Fix keyboard hold events targeting wrong item Aug 30, 2025
@hius07

hius07 commented Aug 30, 2025

Copy link
Copy Markdown
Member

It breaks long-press on a touch device.

@Commodore64user

Copy link
Copy Markdown
Member Author

I didn't think of that.

Two methods with early returns based on touch/non-touch?

@Commodore64user

Copy link
Copy Markdown
Member Author

Same here @Frenzie, this does leave some devices falling through cracks though, i.e touch devices with keyboards can only use the touch based approach... so not optimal

Comment thread frontend/ui/widget/sortwidget.lua
}
}
self.ges_events.Hold = {
self.ges_events.HoldTouch = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this creates an awkward situation where sometimes this is triggered and the same broken behaviour happens, so yeah, name change is needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so.
Moreover, onHoldNonTouch should not duplicate the code but call item:onHold.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I am telling you, naming it onHold does in fact interfere and break the functionality sometimes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break the functionality sometimes

Could you give more details?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focus Manager triggers onHold with keys

Could you show the code where it's happening?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table.insert(event_keys, { "HoldShift", { { "Shift", "Press" }, event = "Hold" } })
table.insert(event_keys, { "HoldScreenKB", { { "ScreenKB", "Press" }, event = "Hold" } })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
Since in this FocusManager instance you introduce new events bound to certain keys, the correct way would be to disable the default ones provided by FocusManager base class.
To avoid sending 2 different events by one key or key combination.
If I remember correctly, you do this in some other places.
self.key_events[smth] = nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it looks like that we don't do this on regular basis, so I agree with your proposition to rename.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, like and subscribe ;)

Comment thread frontend/ui/widget/sortwidget.lua Outdated
end

local item_idx = idx_offset + focused_row
local item = self.item_table[item_idx]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be used instead?

function FocusManager:getFocusItem()

@Frenzie

Frenzie commented Sep 11, 2025

Copy link
Copy Markdown
Member

Now it also works for touch+keyboard, correct?

@Commodore64user

Copy link
Copy Markdown
Member Author

Yes, works everywhere. Touch, non touch, touch with keyboards, all covered.

@Frenzie Frenzie added this to the 2025.10 milestone Sep 13, 2025
Frenzie pushed a commit that referenced this pull request Sep 14, 2025
…#14314)

### what's new

* Added logic in `init` to override FocusManager's `onHold` key event.
* Implemented the `CalendarDayView:onHoldNonTouch()` method to handle keyboard-triggered hold events by invoking the `onHold()` method on the currently focused calendar item.

### related issues

* fix #14238
* same as #14252
@Commodore64user

Copy link
Copy Markdown
Member Author

7th day... the second coming of koreader is nigh (yeah, I am sprinkling some religious satire as well)

@Frenzie
Frenzie merged commit 44b1b81 into koreader:master Sep 18, 2025
4 checks passed
@Commodore64user
Commodore64user deleted the sortwidget branch September 18, 2025 16:27
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
…koreader#14314)

### what's new

* Added logic in `init` to override FocusManager's `onHold` key event.
* Implemented the `CalendarDayView:onHoldNonTouch()` method to handle keyboard-triggered hold events by invoking the `onHold()` method on the currently focused calendar item.

### related issues

* fix koreader#14238
* same as koreader#14252
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NT hold events borked in SortWidget

3 participants