[SuperEditor] - Make all DocumentNodes immutable (Resolves #2166) #2384
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.
[SuperEditor] - Make all DocumentNodes immutable (Resolves #2166)
For undo/redo and edit transactions to be trustable, the document and its nodes need to be immutable from outside the
Editor
. This PR makes that conversion.Replacing nodes
By making nodes immutable, each node can no longer be directly updated for things like changing text, indent, etc. Instead, every time a change is made to a node, the previous node must be replaced by the new node in the document. For that reason, a lot of the changes in this PR is focused on switching from direct node manipulation to document node replacement.
This also means that tests need to re-query nodes throughout the test. We should avoid storing nodes as intermediate values in tests, whenever we can, so that we don't accidentally try to look for changes on the same immutable node.
New copy methods
Moving from direct editing of a node to node replacement, we need the ability to
copyWith()
changes. Unfortunately, there's not a clean solution to this because Dart doesn't support method overloading. As a result, to deal with subclasses, we have to declare things likecopyTextNodeWith()
,copyParagraphWith()
, andcopyTaskWith()
. Moreover, each subclass needs to adjust the superclass copy method so that subclass instances don't lose some of their data when the parent class' copy method is called.