mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #715] Documenting that app keys are not overridable by widgets #521
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#521
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @abitrolly on GitHub (Mar 22, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/715
In CustomKeys wiki page it is not mentioned that keys set by
Application.SetInputCaptureare always active and can not be overridden by widgets. As discussed in https://github.com/rivo/tview/issues/662#issuecomment-968158591.EDIT: Here is where the key processing starts in
tview.github.com/rivo/tview@9994674d60/application.go (L309)@abitrolly commented on GitHub (Mar 23, 2022):
It looks like nothing can be overridden by widgets. I add Modal to Pages and set input capture for both of them. When the modal is active, the key is first handled by parent Pages widget and then passed to Modal.
Pressing 'i' to show modal and then
Escgives two messages.This makes it impossible to override shortcuts in a child widget. I expected the keys to be processed by child widgets first. With current behavior the parent widget needs to know about all keys used by child to skip handling them if the child is active.
The defaults override mentioned in CustomKeys work only to change default widget behavior, but not to change the function of keys in the parent widget.
I think that widget compositing vs inheritance is currently not covered.
@abitrolly commented on GitHub (Mar 23, 2022):
Basically the scenario I expected.
nil, the root widget skips processing the key@darkhz commented on GitHub (Apr 16, 2022):
For the scenario you described, I think you could make use of the HasFocus() and GetInputCapture() calls appropriately, i.e. you could check if infobox is focused in the rootpager's InputCapture, and process the keyevent appropriately.
For example:
@abitrolly commented on GitHub (Apr 16, 2022):
@darkhz thanks for the snippet. It solves the problem, but the burden is that all parent widgets should be modified to account for all shortcuts in child widgets. It could work if there is a way to forward event to child widget tree without explicitly mentioning them.
@abitrolly commented on GitHub (Jun 4, 2022):
Here is the diagram of how
tviewcurrently processes key event. There is no event forwarding beyond first root widget, so it is up to the root widget to forward the event further, manage focus etc.appinput doesn't do focus management or any logic for forwarding events between widgets.Markdown source for the diagram.
@abitrolly commented on GitHub (Jun 5, 2022):
Signature of
application.inputCaptureis different fromwidget.inputCapture. Widget handlers are passedsetFocushandler. Not sure how it is supposed to be used. Looks like widgets don't have a reference to main app object to pass focus to another control, and that there is globalSetFocusfunction.@abitrolly commented on GitHub (Jun 5, 2022):
Yes, it is a role of
rootwidget to forward keyboard event to the next. So the next widget decides what of its children have focus to react to.github.com/rivo/tview@9994674d60/grid.go (L266)github.com/rivo/tview@9994674d60/pages.go (L308-L310)So it looks like only the widget knows what element holds the focus, and there is no way to track where focus is globally, like from Application. Or do I miss something?
@abitrolly commented on GitHub (Jun 5, 2022):
So for every widget there are two handlers.
widget.GetInputCapture- empty by default, set by user as described in CustomKeyswidget.InputHandler- implements widget keysNow the problem is that
widget.InputHandlerdoesn't return anything, so it is impossible to tell if a widget processed the key. So my scenario where event of forwarding unprocessed events to parents doesn't work.@abitrolly commented on GitHub (Jun 5, 2022):
Another problem is that
app.GetFocus()returnsPrimitive, which doesn't haveGetInputCapturemethod. So I am blocked with my top-down event processing idea.github.com/rivo/tview@9994674d60/application.go (L726)@rivo commented on GitHub (Jun 10, 2022):
The top-down implementation was made based on #421 and I have to agree it should be possible to intercept key presses at any level of the widget hierarchy regardless of what's happening further down.
Going back to the original question, I'm trying to understand your reasoning for giving a key a different function in a higher-up "container" class such as
Pages. It looks like you want Esc to close the application but not if theinfoboxis open. I have a feeling such a context-dependent redefinition of a key can lead to frustrations of the user (e.g. accidentally closing the application) — but let's go with it for now. Why do you process Esc inPagesthen instead of inApplication?@rivo commented on GitHub (Dec 17, 2022):
@abitrolly Is this issue still relevant?