jupyterlab/lumino

Focus new tab every time current tab is changed

andrii-i opened this issue ยท 2 comments

Let multiple tabs exist on a tab bar. If one of them is current and focused and it is closed, focus automatically reverts to the document body (body), not to the new current tab.

Part of the jupyterlab functionality such as hotkeys relies on relevant element being focused. As a result of next tab not getting focus, you can't use "close tab" hotkey (option + W) more than once in a row (please see issue #6648 and discussion in it).

Reverted jupyterlab PR 7349 attempted to fix this by listening to currentChanged messages and activating a "changed to" widget. But Lumino fires multiple currentChanged messages in a quick succession any time tab is closed programmatically so there's a raise condition on jupyterlab side (see discussion in PR 7349 and in PR 7684 that reverts it).

Lumino has access to source of truth, currentIndex parameter in TabBar / correct sequence of calls to set currentIndex(), so focusing a tab every time it becomes current seems like it would solve the problem (for example, inside set currentIndex() call). If you have other thoughts on how to fix this or if I'm missing something in my reasoning, please let me know.

/**
* Set the index of the currently selected tab.
*
* #### Notes
* If the value is out of range, the index will be set to `-1`.
*/
set currentIndex(value: number) {

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! ๐Ÿค—

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! ๐Ÿ‘‹

Welcome to the Jupyter community! ๐ŸŽ‰

Side note: the focus change after changing tab was implicated in some performance issues in my profiling. A change to the status quo may help or make things worse, in any case we want to run a manual benchmark so please tag me on a PR if you are planning to work on it.