-
Notifications
You must be signed in to change notification settings - Fork 13
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: extract nested slices #1821
Conversation
Fix for the util method `extractSlices`. When extracting slices, we need to adjust the ranges of marks that appear after each slice in the document. In order to do this, we keep track of the ranges that are to be deleted and then loop over them, adjusting the mark ranges as needed. However, when we have nested slices, each slice may be split by another slice, causing a slice to have multiple ranges. In this case, the list of ranges to be deleted would be overlapping, and thus eventually cause the mark ranges to be adjusted incorrectly. This fix normalizes the list of ranges to be deleted before we start updating mark ranges by first sorting those ranges and then merging overlapping ranges into each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat!
02282e1
to
1a377b6
Compare
1a377b6
to
ebd358d
Compare
packages/@atjson/util/src/index.ts
Outdated
@@ -390,6 +400,24 @@ export function extractSlices(value: { | |||
}); | |||
} | |||
|
|||
// Normalize the ranges again, as we may have extended ranges into each other | |||
// First sort the ranges | |||
rangesToDelete = rangesToDelete.sort(compareRanges).reduce((acc, range) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a for loop here for performance and clarity reasons, but I don't care that much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this!
2868590
to
95b081e
Compare
Fix for the util method
extractSlices
. When extracting slices, we need to adjust the ranges of marks that appear after each slice in the document. In order to do this, we keep track of the ranges that are to be deleted and then loop over them, adjusting the mark ranges as needed.However, when we have nested slices, each slice may be split by another slice, causing a slice to have multiple ranges. In this case, the list of ranges to be deleted would be overlapping, and thus eventually cause the mark ranges to be adjusted incorrectly. This fix normalizes the list of ranges to be deleted before we start updating mark ranges by first sorting those ranges and then merging overlapping ranges into each other.