Skip to content

Commit

Permalink
Fix edge case for zero-length decoration in empty leaf.
Browse files Browse the repository at this point in the history
This change ensures that a zero-length decoration is never treated as encompassing the entire leaf,
handling an edge case where an empty decoration inside an empty leaf was being treated
as encompassing the entire leaf and thus preventing the "before" and "after" leaves
we would otherwise see (when a zero-length decoration is applied to any non-empty leaf).

This fixes issues encountered in the `slate-page-decorations` library for the edge case
of an empty paragraph node being located on the edge of a page boundary.
  • Loading branch information
jemc committed Mar 31, 2022
1 parent ce63a08 commit bc6252b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/slate/src/interfaces/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ export const Text: TextInterface = {
const offset = o
o += length

// If the range encompases the entire leaf, add the range.
if (start.offset <= offset && end.offset >= o) {
// If the range encompases the entire leaf (and the range is non-empty), add the range.
if (
start.offset <= offset &&
end.offset >= o &&
start.offset < end.offset
) {
Object.assign(leaf, rest)
next.push(leaf)
continue
Expand Down

0 comments on commit bc6252b

Please sign in to comment.