Use correct parent depth when dropping context #25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ocavue-fix-replace-with2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pull request addresses two issues in
replaceRangerelated to the context being dropped.The first issue arises when ProseMirror fails to drop the context if the paste target is sufficiently deep. This bug is shown in the following video:
https://github.com/ProseMirror/prosemirror-transform/assets/24715727/a577355b-8b22-4fdb-98e9-65d7342a5cb0
When pasting
<blockquote>one</blockquote>into an emptyblockquotethat inserts a list item (i.e., Case 2 and Case 3 in the video). The defining context is not dropped as expected, leading to an unexpected nested blockquote structure.In this line, the defining context is derived from
$from.node(preferredTargetIndex). However, it appears thatpreferredTargetIndexis merely an index of various depths, and it doesn't necessarily represent a valid depth. I replacedpreferredTargetIndexwithMath.abs(preferredTarget) - 1, following a similar logic here.The second issue is shown in the video below:
https://github.com/ProseMirror/prosemirror-transform/assets/24715727/bc165ecb-06fe-4d2a-851e-8f4e8349ffc7
The source code for this demo can be found here. In this demo, a blockquote node has an attribute to mark its border color.
When copying
red lightblueand pasting them into a gray blockquote, I expected the gray color to be dropped and replaced by the red color. However, the behavior is inconsistent. If the gray blockquote is inside a nested blockquote (i.e., Case 2 and Case 3), it doesn't get dropped.I resolved this issue by comparing not only the node types of the incoming node and the existing context, but also their attributes. I replaced
(...).type != typewith!type.sameMarkup(...)in this line.I have included the demos from the two videos as test code in this PR. I appreciate your time in reviewing this PR. I acknowledge that I still have a lot to learn and I warmly welcome any corrections. Thank you!
Thanks! Merged as
fae874cf09@marijnh Thanks for merging my PR. Could we consider publishing a new version to include these changes?
Certainly. I've tagged 1.7.5
Thank you very much
Pull request closed