Fix not being able to type in code cell after switching from text #17590
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #17579 (there are some perf issues mentioned there that this doesn't specifically address, we can follow up to see if those are still happening after this fix goes in)
This was introduced by #17180
The problem here is that the
onCellMarkdownModeChanged
andonCellPreviewModeChanged
callbacks are being called every time we switch cells - even if the text cell in question isn't active. InfocusIfPreviewMode
there was logic added that gets the current window selection and then replaces it with a new selection for the text cell - but this means that if we're moving into a code cell this event is still being fired and thus we're still running the code to get the current selection (which is now on the code cell) and replacing it with the saved element nodes from the text cell (which aren't even valid anymore since we've moved off of edit mode for the text cell)(this only happens in WYSIWYG mode because of the check on line 512 which only runs this code if there's a saved richTextCursorPosition)
The fix is simple enough...we only want to do this if the current cell is the active one. This seems to fix the issue but we should be looking at all the changes here closely (especially those in the callbacks) and ensuring we aren't going to have any other similar issues.