[ReaderHighlight, Config, Menu] NT: stop text selection before any reflow action occurs#14949
Conversation
| function ReaderMenu:onShowMenu(tab_index, do_not_show) | ||
| -- Note: on devices with DPad, we could start text selection and then trigger a reflow | ||
| -- (e.g., change typeface) which will cause pandemonium to ensue (invalid coordinates). | ||
| self.ui:handleEvent(Event:new("StopHighlightIndicator", {args=true})) |
There was a problem hiding this comment.
Feels a bit a too quick solution to "infect" these other modules with something quite unrelated (currently, StopHighlightIndicator is used only in readerhighlight).
May be you could, in readerhighlight, if ifHasDpad, add (ie. in init(), like the one we discovered in InputText) handlers for these events (self.onShowMenu = function() self:onStopHighlightIndicator(true) end). It may work as readerhighlight is loaded before many other modules in readerui.
There was a problem hiding this comment.
It may work
it doesn't
There was a problem hiding this comment.
But maybe a wrapper could be used, i'll have a look later as i have places to be now ;)
There was a problem hiding this comment.
(I could not find a good idea, but have a go. But a user-patch-like wrapper might be a bit ugilier than your current solution.)
|
Can the indicator be stopped in the |
|
Although reflow is the main concern, is not just that. The crosshairs need to be stopped before going anywhere else really, book map, toc, etc. Edit: for a second i was wondering, why is @poire-z giving a thumbs up to his own post? Then i realised the truth ;) |
So, we need to find another solution... |
|
Have you got any other brilliant ideas though? This seems the lesser of two evils. And I don’t even see how it’s “infecting” anything. |
|
If you need it for ToC, Bookmap... you'll need to put your And with your current solution, on any touch device, we would get that event send to all the modules for nothing (sending events costs a bit of cpu). No brilliant idea, but it's your PR and for you to find it :) |
|
I have deliberately kept Gestures out of this as I believe it is much more unlikely for someone to combine text selection through DPad and Gestures.. in any case, it would be as simple as sending another event similar to Hotkeys..
already did ;) |
Right, sorry for that :) Anyway, I find the wrapping uglier. |
| end | ||
|
|
||
| main_menu.touch_menu_callback = function () | ||
| self.ui:handleEvent(Event:new("CloseConfigMenu")) |
There was a problem hiding this comment.
even here we still send an event.. but whatever
There was a problem hiding this comment.
I agree this one does not need to be an event, its name is the name of its target, we could call it directly. (But not for you to do in this PR.)
(Events are good for a generic... event, that may interest multiple modules (even if there is currently only one catcher, thinking about the future if the event is generic)
|
and, I am not much interested in how you handle wiping you' ass but #FreeTheCPU ;) |
| function HotKeys:onHotkeyAction(hotkey) | ||
| -- Note: we could have started text selection and then trigger a reflow through hotkeys (e.g., increase | ||
| -- font-size) which will cause pandemonium to ensue (invalid coordinates). | ||
| self.ui:handleEvent(Event:new("StopHighlightIndicator", {args=true})) |
There was a problem hiding this comment.
Your plugin can also access self.ui.highlight.
There was a problem hiding this comment.
yes, but that seems a lot less clean...
There was a problem hiding this comment.
You are already not the only one (if the plugin works when in filemanager, it should additionally have if self.ui.highlight then):
plugins/qrclipboard.koplugin/main.lua: if self.ui.highlight then
plugins/qrclipboard.koplugin/main.lua: self.ui.highlight:addToHighlightDialog("12_generate_qr_code", function(this)
plugins/hotkeys.koplugin/main.lua: self.ui.highlight.key_events.StartHighlightIndicator = nil -- remove 'H' shortcut used for highlight indicator
plugins/vocabbuilder.koplugin/main.lua: if settings.with_context and self.ui.highlight then
plugins/vocabbuilder.koplugin/main.lua: prev_context, next_context = self.ui.highlight:getSelectedWordContext(15)
plugins/vocabbuilder.koplugin/main.lua: if self.ui.highlight.selected_text and self.ui.highlight.selected_text.text then
plugins/vocabbuilder.koplugin/main.lua: highlight = util.cleanupSelectedText(self.ui.highlight.selected_text.text)
There was a problem hiding this comment.
I am guilty of the qr one, but then again that is adding an element to that menu. the hotkeys ones have been the hacks to solve the overriding, and now to move the hardcoded shortcuts you are making me move there ;)
There was a problem hiding this comment.
But this is absolutely not an issue. You were guily of nothing.
But you'd be guilty now to use an event when the canonic thing (what I've shown :)) is to access self.ui.highlight directly, including in plugins.
There was a problem hiding this comment.
tight coupling, don't talk to strangers (Law of something or other), off the top of my head
There was a problem hiding this comment.
Yes.
(These principles are good!)
There was a problem hiding this comment.
I don't know man, seems like reaching across the dinner table and grabbing someone else's wine, but okay ;), if that's the French style, well..
|
As this is a first, heads up, squashing and merging in five 😬 |
|
I feel like i disappointed granddad. ;) |
|
You did, but I can take it :) |
| function HotKeys:onHotkeyAction(hotkey) | ||
| -- Note: we could have started text selection and then trigger a reflow through hotkeys (e.g., increase | ||
| -- font-size) which will cause pandemonium to ensue (invalid coordinates). | ||
| if self.ui.highlight then self.ui.highlight:stopHighlightIndicator(true) end |
There was a problem hiding this comment.
Shouldn't this be invoking self.ui.highlight:onStopHighlightIndicator(true)?
As-is, I get:
02/18/26-17:00:49 ERROR An error occurred while executing a handler:
plugins/hotkeys.koplugin/main.lua:92: attempt to call method 'stopHighlightIndicator' (a nil value)
hotkeys:onHotkeyAction
stack traceback:
plugins/hotkeys.koplugin/main.lua:92: in function <plugins/hotkeys.koplugin/main.lua:89>
[C]: in function 'xpcall'
frontend/pluginloader.lua:97: in function 'handleEvent'
frontend/ui/widget/container/widgetcontainer.lua:83: in function 'propagateEvent'
frontend/ui/widget/container/widgetcontainer.lua:101: in function 'handleEvent'
frontend/ui/uimanager.lua:910: in function 'sendEvent'
frontend/ui/uimanager.lua:53: in function '__default__'
frontend/ui/uimanager.lua:1437: in function 'handleInputEvent'
frontend/ui/uimanager.lua:1537: in function 'handleInput'
frontend/ui/uimanager.lua:1581: in function 'run'
reader.lua:294: in main chunk
There was a problem hiding this comment.
YEESSS, how did that happen?
There was a problem hiding this comment.
fixed now, thank you. fix should be in the next nightly.
* refactor onStopHighlightIndicator so it returns early * stop text selection when opening menus or triggering hotkeys * use self.ui.highlight (naturally) * remove duplicated setDirty

what's new
Added calls to
self.ui.highlight:StopHighlightIndicator()inReaderConfig:onShowConfigMenu(),ReaderMenu:onShowMenu(), andHotKeys:onHotkeyAction()to ensure text selection is stopped before any reflow actions that could invalidate highlight coordinates.Updated
ReaderHighlight:onStopHighlightIndicator()to return early if there is no current indicator position, preventing unnecessary processing and errors.This change is