term.js
term.js copied to clipboard
Removed stopPropogation, cancelBubble from term.js
Hi, I'm writing cloud file manager and using terminal, but it has no ability to run programs such mc or vim. So I try adopt term.js to use it.
But I have a problem with cancelling event it term.js. Listeners of Terminal is added to document, it's not very good, my listeners doesn't work because they are canceled in this code:
if (ev.stopPropagation) ev.stopPropagation();
ev.cancelBubble = true;
Is it realy needed? Maybe there is some way to drop them? Or add listeners to terminal element?
Thank you.
-1 Your events should only be getting cancelled if the terminal has focus. This is how it should be as the terminal needs to intercept the key strokes and send them to whatever is handling your connection. Most every keystroke is converted into a code and sent so this behavior is both intended and required. If you have other events which need to be triggered by key you will need to remove focus from the terminal first.
You said that
This is how it should be as the terminal needs to intercept the key strokes and send them to whatever is handling your connection.
But it works good without stopPropogation and cancelBubble. In my project there is use case:
Shift+~pressed- modal window with terminal is opend,
- when I press
Esc - modal window with terminal should close. This is how thing is done right here.
It's not one of cases it's common case. Terminal almost always would be used on a page where a lot of other key handlers and it's need to be considered.
I don not understand why things like stopPropogation and cancelBubble should be if everything works good without them and they makes life harder?
Anyway, how you suggest me to achieve my use case with removing focus from terminal?
When you press ESC, the terminal traps that keystroke (if it has focus) and has already sent it to the server and thus the keystroke should be considered "consumed". If you prefer to let that sort of thing happen you can, but this is not something that should ever be merged into the mainline term.js because it has many unintended consequences. If other things are listening for that keystroke, they could do something like close the terminal (in your case) when all you wanted to do was exit insert mode in Vi. As I do not know exactly what you are doing with the terminal this may be irrelevant, but for general use the cancelBubble and stopPropagation must stay.