Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

undo image paste in rendered notebook markdown will just remove the attachment #180866

Open
amunger opened this issue Apr 25, 2023 · 3 comments
Open
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug notebook-markdown
Milestone

Comments

@amunger
Copy link
Contributor

amunger commented Apr 25, 2023

Testing #180759

  1. paste an image into a markdown cell to create an attached image
  2. render the markdown cell
  3. ctrl+z to undo
    馃悰 broken image link

likely because the undo operation isn't able to edit the markdown content, but the undo operation probably shouldn't happen at all

@mjbvz mjbvz self-assigned this Apr 26, 2023
@mjbvz mjbvz added this to the May 2023 milestone May 1, 2023
@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label May 3, 2023
@mjbvz

This comment was marked as outdated.

@mjbvz
Copy link
Contributor

mjbvz commented May 16, 2023

I've investigated this issue but am unsure how best to fix it (or even which layer to fix it in). The issue can also happen for normal workspace edits and is not specific to drop or paste.

Here's my understanding of the issue:

  1. On paste, we apply a workspace edit. This workspace edit both adds text to the current cell and updates that cell's metadata

  2. When you then enter into preview mode and press undo, an undo operation is requested for the entire notebook (the file://*.ipynb resource)

  3. At the start of the undo call, the undoRedoService is in the following state:

Screenshot 2023-05-16 at 3 06 49 PM

Notice how there are two undo stacks: one for the cell and one for the notebook. The edit in each of these two stacks has the same groupId. However critically, the edit for the entire notebook (the one in the file://*.ipynb stack) has a higher groupOrder

  1. When trying to undo, we now check if there are any other edits in the same group that should also be undone:

However this code ends up not finding the cell text change because its group order is lower. This means we only undo the metadata change, causing the broken image


This same flow works correctly if the cell is still in edit mode and focused. The key difference is that when the cell is being editing, the undo operation is instead requested for the notebook cell itself (vscode-notebook-cell:...) instead of for the entire notebook. This means that the above code finds the metadata edit on the entire notebook and also undoes it

@rebornix @jrieken For fixing this, should we try to make the NotebookTextModel push a single edit for the entire workspace edit? Right now it ends up pushing two elements into the undoRedoService: one for the metadata change (a IWorkspaceUndoRedoElement) and one for the cell text change (a IResourceUndoRedoElement)

Also open to other suggestions as I'm not too familiar with this area of our code

@mjbvz mjbvz modified the milestones: May 2023, June 2023 May 24, 2023
@rebornix
Copy link
Member

rebornix commented Jun 9, 2023

@mjbvz thanks for the great analysis and it turns out that our undo/redo support (along with notebook.undoRedoPerCell setting) is not sufficient.

By default notebook.undoRedoPerCell is enabled, so the cell doesn't share the undo/redo stack with the notebook document. If we turn it off, then I think the scenario you showed above works.

The challenge here is when it's enabled (default value), cell text model and notebook text model have separate undo/redo stack, which works fine until we create an undo/redo group which pushes UndoElement to both stacks.

However this code ends up not finding the cell text change because its group order is lower. This means we only undo the metadata change, causing the broken image

Conceptually this is no different from creating an undo/redo group which pushes UndoElements to two separate files' undo stacks. I wonder if we should tweak this piece of code to make it work. cc @alexdima

@rebornix rebornix assigned alexdima and unassigned jrieken and Yoyokrazy Jun 9, 2023
@mjbvz mjbvz modified the milestones: June 2023, July 2023 Jun 22, 2023
@mjbvz mjbvz modified the milestones: July 2023, August 2023 Jul 18, 2023
@mjbvz mjbvz modified the milestones: August 2023, September 2023 Aug 29, 2023
@mjbvz mjbvz modified the milestones: September 2023, October 2023 Sep 26, 2023
@rebornix rebornix modified the milestones: October 2023, November 2023 Oct 24, 2023
@mjbvz mjbvz modified the milestones: November 2023, December 2023 Nov 21, 2023
@mjbvz mjbvz modified the milestones: December / January 2024, February 2024 Jan 22, 2024
@rebornix rebornix removed this from the February 2024 milestone Feb 21, 2024
@rebornix rebornix added this to the March 2024 milestone Feb 21, 2024
@mjbvz mjbvz modified the milestones: March 2024, April 2024 Mar 25, 2024
@mjbvz mjbvz modified the milestones: April 2024, May 2024 Apr 22, 2024
@mjbvz mjbvz modified the milestones: May 2024, June 2024 May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug notebook-markdown
Projects
None yet
Development

No branches or pull requests

6 participants