eclipse-theia/theia

Issue: vscode.window.activeTextEditor is undefined When Focused on a Jupyter Notebook

garyb9 opened this issue · 9 comments

Description:

When focusing on a Jupyter Notebook in Theia, the vscode.window.activeTextEditor object is unexpectedly undefined. However, this behavior is inconsistent: when switching focus from a regular file to a Jupyter Notebook, vscode.window.activeTextEditor is not undefined (though it still has issues, such as those described in #14475 and #14476).

This issue was previously fixed for cases where activeTextEditor was constantly null when focused on a notebook. While that fix ensured that activeTextEditor is now defined when a notebook is focused, it appears the issue has partially returned, as activeTextEditor is not always defined in this scenario.

Steps to Reproduce:
1. Open Theia and focus on a Jupyter Notebook.
2. Log the value of vscode.window.activeTextEditor.
3. Observe that editor is undefined.
4. Now switch focus to a regular text file (e.g., .txt, .json, or .js).
5. Switch focus back to the Jupyter Notebook.
6. Log vscode.window.activeTextEditor again.

const editor = vscode.window.activeTextEditor;
console.log(`editor: ${editor}`);

Expected Behavior:

The vscode.window.activeTextEditor object should always be defined when a notebook is focused, as it is when a regular file is focused.

Observed Behavior:
• When first focusing on a Jupyter Notebook:
• vscode.window.activeTextEditor is undefined.
• When switching focus from a regular file back to the Jupyter Notebook:
• vscode.window.activeTextEditor is not undefined, but still contains issues (see related bugs about selection and isEmpty).

This inconsistent behavior makes it difficult for extensions and developers to reliably interact with the activeTextEditor object when working with Jupyter Notebooks.

Impact:

This bug affects extension development and functionality that relies on the activeTextEditor object. While the prior fix ensured that activeTextEditor was no longer consistently null when focused on a notebook, this partial regression has introduced additional challenges.

Additional Context:
• This issue was originally fixed a few PR's back, which resolved activeTextEditor being consistently null for notebooks.
• The current behavior shows a partial regression, with activeTextEditor sometimes being undefined when focusing directly on a notebook.
• This issue is limited to Jupyter notebooks and does not occur with regular text files.

Request:

Please investigate why vscode.window.activeTextEditor is still undefined when focusing on a notebook in certain scenarios, and ensure that it is consistently defined in all cases.

ok do i understand this correctly. The issue right now is, that switching back to an notebook editor where previously a code cell was selected the acitiveTextEditor is now undefined instead of directly going back to being the editor of the selected code cell?

But if the previously selected cell is a markdown cell, then it stays as undefined until the user focuses a cell editor?

Not quite, its simpler than that -

If i only have a notebook tab open and i select some text in a cell - acitiveTextEditor is undefined
if i then open another file (i used a .py file), select some code within it, go back to the open notebook tab - acitiveTextEditor is NOT undefined (i.e. has the correct data of that notebook)

its like the acitiveTextEditor isnt triggered unless a regular, not a notebook file, tries to access it

with what theia version did you test that? Because i can not reproduce the case you are describing. Having one notebook open and selecting some text has the correct active text editor set for me

Happens quite often, here's the about -
image

Moreover, if i dont touch theia for the night and i come back the next day and i have these tabs open:
image

the issue comes back again.
i need to manually switch to the py file, come back to the notebook and only then editor is operational

It could be the linked PR could fix some of the problems. But probably not the one that the notebook just stops working after some time. Havn't heard about that before and to be honest i have no idea how that could happen.
If you find the time could you test with the PR?

Sure, when can i get the new Theia version?
Also - this happens both in local theia installment and in plotly dash app, but let me test it after you release your other fixes.
If it won't help - will you be open to a quick call so i could show you?

for testing you either have to build theia yourself or i can create a next-release after the PR is merged.
Sure if this does not fix some of the issue lets have a quick call

Sure
Just let me know when this is merged and how can i install the next-release