xtermjs / xterm.js

A terminal for the web
https://xtermjs.org/
MIT License
17.72k stars 1.63k forks source link

Expose `onBlur` event #5215

Open jtbandes opened 2 hours ago

jtbandes commented 2 hours ago

I would like to clear the selection when the terminal loses focus. I was able to make it work like this:

    (terminal as any)._core?.onBlur?.(() => {
      terminal.clearSelection();
    });

It would be nice to expose this onBlur event on the public Terminal interface so people don't have to use private API for it.

(Probably onFocus too, I just didn't happen to need that one.)

Tyriar commented 2 hours ago

I think in the past we didn't add this as you can just add regular dom listeners to Terminal.element after calling Terminal.open:

https://github.com/xtermjs/xterm.js/blob/41e8ae395937011d6bf6c7cb618b851791aed395/typings/xterm.d.ts#L831-L834

jtbandes commented 2 hours ago

I tried that as well, but it didn't work. Example: https://codesandbox.io/p/sandbox/xtermjs-test-forked-rfznf7

jtbandes commented 2 hours ago

Ah I see, it works with terminal.textarea but not terminal.element. Thanks! 🎉