« get me outta code hell

(breaking, very) Fix how text inputs bubble events - tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/ui/Root.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-09-12 13:39:14 -0300
committerFlorrie <towerofnix@gmail.com>2018-09-12 13:39:16 -0300
commita4020ad79c4c9f275c960882bfec8bb473d98d9f (patch)
tree2f89bcff49105fefaa3027d6e1e5fa3e90efe1df /ui/Root.js
parent68d5c75dce1c950468d07241261fb9f8c8e3d39b (diff)
(breaking, very) Fix how text inputs bubble events
This is extremely super duper very breaking in that it reverses the
order that keyboard events are bubbled.

This fixes an issue in the following situation: You have a focus element
which captures keyboard input. When the X key is pressed, a text input,
which is a child (directly or indirectly) of it, is selected and has its
value emptied. As the user types into that text input, if they press the
X key, the handler on the focus element will detect this, and clear and
select the text input - interrupting the user's typing.

The situation is fixed in this commit by making the text input avoid
bubbling events when text is entered. I'm not sure this is 100%
complete, because arrow key events and the like are still bubbled, but
those aren't difficult to change later. The breaking fundamental change
here is that keyboard events are now bubbled from the top element down.
Before, a parent element could deny child elements from responding to
the event; now the child can deny the parent.
Diffstat (limited to 'ui/Root.js')
-rw-r--r--ui/Root.js2
1 files changed, 1 insertions, 1 deletions
diff --git a/ui/Root.js b/ui/Root.js
index a6b3acf..7e031d3 100644
--- a/ui/Root.js
+++ b/ui/Root.js
@@ -27,7 +27,7 @@ module.exports = class Root extends DisplayElement {
   handleData(buffer) {
     if (this.selectedElement) {
       const els = [
-        ...this.selectedElement.directAncestors, this.selectedElement]
+        ...this.selectedElement.directAncestors, this.selectedElement].reverse()
       for (const el of els) {
         if (el instanceof FocusElement) {
           const shouldBreak = (el.keyPressed(buffer) === false)