microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.45k stars 29.35k forks source link

When "ctrl+enter" or "shift+enter" it run the wrong cell #133038

Closed Tirbo06 closed 2 years ago

Tirbo06 commented 3 years ago

Environment data

VS Code version: 1.60 Jupyter Extension version (available under the Extensions sidebar): v2021.8.1054968649 Python Extension version (available under the Extensions sidebar): v2021.7.1060902895 OS (Windows | Mac | Linux distro) and version: Windows 10: 21H1 Python and/or Anaconda version: 3.8.10/3.9.6 Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv Jupyter server running: Local | Remote | N/A: Local and remote

Expected behaviour

Run the selected cell when "ctrl+enter" or "shift+enter".

Actual behaviour

Sometimes, when "ctrl+enter" or "shift+enter" to run a cell, it run the wrong cell. It seems to me that it is running the last cell ran.

Steps to reproduce:

Hard to reproduce as it is happening randomly. I would suspect it to happen after a high memory consumption (reaching to max) that will make it bug until we restart the apk/computer.

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

``` ```

DonJayamanne commented 3 years ago

Thanks for filing this issue. Are you using a notebook or the Interactive Window?

greazer commented 3 years ago

Likely an interactive window problem. @Tirbo06, let us know what you know.

Tirbo06 commented 3 years ago

It happens in Jupyter Notebooks

Tirbo06 commented 3 years ago

I will try to edit the post with a gif when it happens again

ianholst commented 3 years ago

I've also been having this happen, and I can't figure out the pattern either. Sometimes it gets stuck so that no matter which cell I tell it to run, it just keeps running the same one. This stops when I switch to another tab and back.

fredericohorst commented 3 years ago

I'm also having this issue.

greazer commented 3 years ago

VSCode core handles the ctrl+enter and shift+enter shortcuts so transfering there.

munro commented 3 years ago

Having the same issue, I've tried playing with the shortcuts, but I can't seem to fix it. It really makes VSCode Notebooks unusable 😞

It seems like there's some discrepancy with where the editor cursor is, and where the notebook thinks the cursor is when executing.

wenkangmq commented 3 years ago

For me, default keybinding ctrl+Enter runs the above(previously edited) cell instead of the current one. Resetting keybinding make the problem go away for a while but then it happens again radomly.

Notebook users run each cell every step of the way, this bug really makes it unusable. please consider make this bug a high priority one.

roblourens commented 3 years ago

I can't reproduce this. A gif would really help. @yuanchongtt had a screenshot of a notebook with the editor focus and cell focus out of sync.

image

Is that what people are seeing? Would really like to see a gif of how people get into that state

theonlypoi commented 3 years ago

I have noticed similar behaviour. I don't know if it's actually the problem. But this happens when I create one cell using code button that appears on hovering over the cell and then create another cell using the code button at the top.

Steps to reproduce:

  1. Create a new notebook.
  2. Delete the first cell that appears.
  3. Use +code button on the screen to create a cell (execute it with Ctrl + Enter).
  4. Then use +code button (that appears on the top bar) to create another cell.

Now the cursor appears to stop on the first cell. This is for a completely new notebook. But unable to reproduce this behaviour when the notebook already have some cells.

I don't know how to create a gif but I hope the steps I mentioned will be helpful.

wenkangmq commented 3 years ago

I think the problem is that vscode is not focusing on the current cell that's being edited, the result of that is ctrl+enter runs the other cell that was wrongfully considered "current cell"

here is the gif

As can be seen from the gif, after editing the other 2 cells, the "current cell" with the blue bar is still the old one.

I don't know how to trigger this, but it happens from time to time.

DonJayamanne commented 3 years ago

@roblourens I'm running into this pretty consistently, will ping when today when I run into this.

jazzlw commented 3 years ago

This issue has been killing me. makes the vscode notebooks almost unusable. I generally resort to manually clicking the play button on a given cell to get it to run. This generally does not fix the behavior or change focus, but sometimes it does. Seems very stochastic overall.

jazzlw commented 3 years ago

Added detail: Often this seems to be caused by a clear separation of focus, where the blue vertical bar focus indicator is not on the cell currently being edited, as in the gif above.

However, at other times, the blue cell focus indicator is correct and a different cell is still run, with no visual indication of which one it will be.

roblourens commented 3 years ago

I am still not able to repro this. People who see this, cold you try downloading the Insiders' build and tell me whether it happens there? https://code.visualstudio.com/insiders

DonJayamanne commented 3 years ago

@roblourens i think https://github.com/microsoft/vscode/issues/133026 is a dup of this. Possible the contexts weren't working correctly. E.g. i run into issues where selecting a cell and hitting the DD to delete a cell wouldn't work, until and unless i closed and re-opened the notebook. FYI - I haven't been able to replicate this, since monday.

jazzlw commented 3 years ago

I've switched to insiders and haven't had the problem again yet! I'll message back again if it happens again in the insiders version.

roblourens commented 3 years ago

Moving to October - seems like this has still been observed once or twice in Insiders, but there's nothing that I can do here right now. Please continue to report it if you see it and let me know what actions you took.

wenkangmq commented 3 years ago

I have been using a fresh install of the 1.61.0-insider build on Fedora for a week. Only extensions are Dracula theme, phtyon extension, and tabnine, also no settings sync. I haven't encountered this bug yet.

rikardfranksson commented 3 years ago

Pinging @roblourens

I've been plagued by this issue for some time now, on the Insiders build as well. I've managed to reproduce it consistently and below are some screenshots of how I reproduce it.

  1. Create a new cell and run it

1

  1. Click the first cell to select it and then create a new cell below

2

  1. Clicking the new cell places the cursor in it and allows for editing while the first cell remains selected

3

  1. Shift+enter in the new cell incorrectly runs the first cell

4

  1. Cell selection/run-context is now messy and shift-enter behavior unpredictable.

5

I do note that the cell selection/thick left border is unaligned with my cursor and clicking cells back and forth - clicking the border as well as input and output - does not reset the context. I.e., the state of unpredictable shift-enter behavior is difficult, if not impossible, to get out of.

Hope this helps.

roblourens commented 3 years ago

Thanks for the screenshots! I see you have an update pending in that Insiders build, can you check the date on it? (Help > About)

I've found two ways to get the editor and list focus out of sync. But neither is what we are seeing here.


I don't think either of these are worth taking for this release. I still don't see how it's possible to insert a cell and end up with that cell not focused

rikardfranksson commented 3 years ago

Thanks for the screenshots! I see you have an update pending in that Insiders build, can you check the date on it? (Help > About)

Version: 1.61.0-insider Date: 2021-09-16T08:31:28.161Z

I still don't see how it's possible to insert a cell and end up with that cell not focused

Are you referring to my situation? If so, is there anything else I can do or test to ease your debugging?

Edit: to clarify my screenshots, this is what I did (not necessarily the same steps as the screenshots)

  1. Create a cell and run it
  2. Select cell 1
  3. Create a new cell using the plus
  4. Click the new cell to place the cursor in it - the first cell remains selected
  5. Shift+enter now runs the first cell and selecting new cells does not ensure they are run by shift+enter
roblourens commented 3 years ago

That's a little out of date, Insiders is updated every day, would appreciate if you update to get the latest and try again.

jazzlw commented 3 years ago

Have been using insiders for a while and not been having the problem but just had it again today... I'm surprised to see my info date says 9-26 since I thought I'd just updated. I'll update again and report back if the problem continues

Version: 1.61.0-insider (Universal) Commit: 214ac689ca9874a8a4be386f73d5cb60e15af25e Date: 2021-09-28T05:14:06.244Z Electron: 13.4.0 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Darwin x64 17.7.0

harripj commented 2 years ago

I am still having this problem running on 1.62.3, Windows. It has been plaguing me for a while. The problem is intermittent and hard to reproduce in my case too. I have noticed that when it happens the thick blue 'active cell' line indicator (on left of cell) remains fixed on a certain cell, despite the creation or clicking on new cells. This is the cell that also executes, so I imagine the two are related. The cell toolbar also remains fixed on this cell despite focussing/clicking on a new cell in my case.

I have attached a screenshot here to better explain my descriptions. image

melihozaydin commented 2 years ago

Having the same issue as well. It's not a big issue as I can close and reopen the notebook to temporarily fix it, but it is annoying as hell.

munro commented 2 years ago

Same, this issue was fixed a bit—but then started happening again recently. 😢

harripj commented 2 years ago

It just happened to me again. I tried to execute a cell above or below a certain cell, but this cell kept executing instead. In fact I noticed that by clicking in the gutter I could move the blue active line and cell toolbar (that I mentioned above https://github.com/microsoft/vscode/issues/133038#issuecomment-976529373) but even though this UI was changed, the wrong cell kept executing. So my last comment maybe somewhat of a red herring!

Another thing I noticed is that I had clicked away to a different program and when I returned to VS Code the problem had sorted itself out and the correct cell would execute.

hamiddashti commented 2 years ago

Same here. Is there any solution found for this issue, rather than closing and reopening the notebook?

david-waterworth commented 2 years ago

@hamiddashti if this is the same problem I reported (https://github.com/microsoft/vscode/issues/136310) then a potential solution is to change focus from vscode to another application and then switch back. I noticed this as each time I encountered the issue I tried to switch to a screen recorder to record and the problem went away. It could well be a different issue though, or behave differently on different platforms (I'm using Linux)

roblourens commented 2 years ago

No reports of this in awhile - closing