Repository: vscode
Issue: Jupyter notebook cell menu incorrect for new cells
Labels: bug,notebook-commands,notebook-celltoolbar

Jupyter notebook cells provide a pop-up mention at the top-left corner of cell when focus is on the cell.
However, the content of the menu fails to update to reflect the current cell. This seems to be a UI event issue.

To reproduce, read these instructions on your phone or a separate window so you don't have to change focus from VS code while following along.

1. Create a new notebook.
2. In the top cell, type, say `import sys`. Notice that the cell menu contains "... &lt;trashcan>".
3. Switch focus away from VS code to another application window. Switch back. Now you see the full Python menu.
4. Use the "+ Markdown" button to add a markdown cell. Type, "example". Notice that the cell menu contains the "&lt;run by line>, &lt;execute cells below>, &lt;execute cells above>, ..., &lt;trashcan>" items.
5. Again switch focus to another application, then back to VS Code. Now you see the "&lt;checkmark>, &lt;split cell>, ..., &lt;trashcan>" menu items.
6. Use "+ Code" to add a Python cell. Notice that the menu again contains only "... &lt;trashcan>".
7. Again switch to another window and back. The proper Python menu appears.

I have found that, sometimes, I can get the menus to reset by clicking onto another cell and back. I find I must frequently do this when adding a Markdown cell.

Here is another variation:

1. Add a Python cell. Type `a = 10`. Switch away from VS code and back again to get the proper menu.
2. Add a Markdown cell below. Notice that the menu contains the Python cell menu items. Switch away and back to get the Markdown cell menu items.

Yet another variation. The above examples all added cells at the bottom. This time, we'll add one in the middle.

1. Select your top Python cell. Add a Markdown cell. You will see the "&lt;run by line>, &lt;execute cells below>, &lt;execute cells above>, ..., &lt;trashcan>" menu.
2. Switch away and back to get the Markdown menu.
3. Add a Code cell below you Markdown cell. You'll get only the "..., &lt;trashcan>" menu.
4. Switch and and back to get the Python menu.
5. Add another Markdown cell. This time you get the Markdown menu immediately.
6. Add a Code cell. You'll get the proper Python menu.
7. Add another Code cell. You'll get the Python menu but without the "Split Cell" item.
8. Add another Code cell. Again the truncated menu.
9. Click on the cell created in 6. Back to the Python menu.
10. Click on the cell added in 7. Still the truncated menu.
11. Click on the cell created in 6. Switch to another app and back to VS Code.
12. Click on the cell added in 7. This time you get the full Python menu.

This behavior does not happen all the time. It only happens for new cells. If you click around your existing cells, you'll see that the cell menu is correct.

In short, it seems that the UI is not receiving some kind of UI event that tells it to switch the hover menu to the version for a newly created cell. The menu seems to lag a bit. We can force an update by switching application focus.

### Workaround

Having incorrect menus is a nuisance. One can often get the correct menu by clicking on another cell, then back. Sometimes switching to another app and VS Code is necessary.

## Environment data

<details>

About dialog information:

```text
Version: 1.91.1
Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
Date: 2024-07-09T22:08:12.169Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Linux x64 5.15.0-113-generic
```

-   Jupyter Extension version (available under the Extensions sidebar): v2024.6.0
-   Python Extension version (available under the Extensions sidebar): v2024.10.0
-   OS (Windows | Mac | Linux distro) and version: Linux Mint 21.3 (also see above)
-   Python and/or Anaconda version: Python 3.10.12
-   Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
-   Jupyter server running: N/A (VS-Code provided server)

</details>