Change:
super.dispose(); dispose(this._editorListeners); <del> this._undoRedoService.removeElements(this.uri); </del> <ins> // Only remove the undo redo stack if we map this cell uri to itself // If we are not in perCell mode, it will map to the full NotebookDocument and // we don't want to remove that entire document undo / redo stack when a cell is deleted if (this._undoRedoService.getUriComparisonKey(this.uri) === this.uri.toString()) { this._undoRedoService.removeElements(this.uri); } </ins> if (this._textModelRef) { this._textModelRef.dispose();

Discussion:
This video shows text in another cell being undone even though focus is in a different cell. Doesn't seem to matter whether "Notebook: Undo Redo Per Cell" is enabled or not ! This video shows that after a cell as been and text has been to it, Ctrl-Z can be used to remove it, but it cannot be redone. You've lost anything typed in that cell permanently. !
Marking as important and a regression as I can't seem to figure out whether the "per-cell" setting is working the way it's intended or not.
Actually it appears that I may have disabled the "per-cell" setting a long time ago and didn't realize it. This may explain both behaviors above. I didn't realize that after changing that setting VS Code must be reloaded for the setting to take effect.
So removing "important" and "regression" for now. Let's just review what the behavior is that we want. It does seem problematic that if you have the setting off, that it doesn't seem possible to restore a cell you may have accidentally deleted. When the setting is on, Ctrl+z seems to work as expected.
After internal discussion, re-marking as important. It's a data loss scenario if you have cell-level undo off.
Possibly related to
With Cell Undo / Redo on (this is the default): Undoing and redoing text per cell works as expected Yes, with my testing Undoing and redoing add / remove of cell works as expected No, see bug 3 Undoing remove of cell via delete button No, see bug 4 With Cell Undo / Redo off: Undoing and redoing text per document works as expected No, see bug 1 Undoing and redoing add / remove of cell works as expected No, see bug 2 Undoing remove of cell via delete button No, see bug 4 Bugs: 1 Two cells in document. Changed from per cell to document mode. Typed in Cell A. Moved to the second cell, hit Undo. Instead of undoing the text, it blew away the second cell. Typing Redo did bring it back. I expected the typing in Cell A to be undone. Note, this bug I don't see after reloading the window. Might be that the setting change mid flow got the stack into a funny state? 2 Two cells in document.

Shift-enter to run and add a new cell. Type in new cell. Ctrl-Z makes the typing go away and eventually the cell. When the cell is fully removed, redo will not restore it, so the typing is lost. Note, I can only replicate this will per cell turned off. With per cell turned on I first need to not be on the current cell to make it go away via Undo. But in that case I can make it go away with Undo and the text is restored with Redo. 3 However with per Cell on the cell + text does come back, but when it comes back it comes back without the per cell undo redo stack with per cell turned on: 4 When removing cell with the delete button, it cannot be restored with undo. This is true with either setting on. This is what I saw in my first pass. My personal ranking in importance would be like so 4 - Clear data loss. In both modes a cell is deleted and I can't get it back and the info in it. Easy to do and damaging. Effects both modes. 2 - Also clear data loss. I find this as a bit less important as I can only repro it with perCell off and I need to Ctrl-Z through the cell to get to the cell loss case so I've already removed what I typed in to the cell to get here. 3 () - Data loss here, but the data loss is not the actual code just the undo redo stack. So I'd vote for less important. 1 - I only reproed this when changing the perCell setting without a reload so an issue, but lesser importance.
Some related issues:
Note I'm going to use this issue specifically to resolve the issue where with perCell mode turned off you cannot restore a cell that was deleted with undo.

The only specific scenarios in this fix are as follows: a notebook document a new cell (type something in it if you want) the cell using the delete button in the toolbar +Z (Run Undo) from a previous cell in the file the cell would not be restored, now it will be Scenario 2: the last cell in a notebook document shift-enter to run the cell and create a new cell some word in the new cell using Undo in that cell, it should walk back the words typed and eventually delete the cell start pressing Redo, it should restore the cell to the document then restore the words typed the cell would not be restored.
thanks for the detailed investigation, they are insightful! For bug 1, you are correct that flipping the setting messed up with the undo/redo state. We register based on the setting which is not updated when we flip the setting. We might want to dispose it and register a new one when the setting changes. For bug 2, with your fix in, I can't reproduce it with the per cell setting off. Not sure if it's similar to bug 1. For bug 3, your comment is accurate. It's like a document and we don't persist them usually when a resource is gone. I wonder if we should fetch and "save" the undo/redo stack for the cell on the cell deletion element in the undo stack.
Reopening to cover the issues with flipping the setting. I'll close after that fix and will cover the bigger issue on persisting undo / redo per cell after delete.
/verified? Still not sure this is working. Is per cell undo supposed to allow undo to affect other cells? Repro: to per cell undo in first cell in second cell +Z Expected it to only affect the current cell with focus. Actually it removes the typing in the first cell.
Otherwise seems to behave more like I'd expect.