File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -356,7 +356,20 @@ export function splitRanges(
356356 if ( containedEnd ) {
357357 let after = range . cloneRange ( ) ;
358358 after . setStart ( splitAtRange . endContainer , splitAtRange . endOffset ) ;
359- if ( ! after . collapsed ) splitRanges . push ( after ) ;
359+ if ( ! after . collapsed ) {
360+ splitRanges . push ( after ) ;
361+ // When splitAtRange is collapsed and falls in a gap between
362+ // ranges, both containedStart and containedEnd are true for
363+ // the range after the gap. The 'middle' portion (from
364+ // splitAt.start to splitAt.end) is also collapsed and gets
365+ // skipped, leaving splitIndex at -1. Without this fix,
366+ // startIndex would be newRanges.length + (-1), incorrectly
367+ // pointing to the previous range. Point to 'after' instead,
368+ // which is the first range at/after the split point.
369+ if ( containedStart && splitIndex === - 1 ) {
370+ splitIndex = splitRanges . length - 1 ;
371+ }
372+ }
360373 }
361374
362375 if ( containedStart ) {
You can’t perform that action at this time.
0 commit comments