This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed
Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -581,12 +581,14 @@ export default class Schema {
581581 getLimitElement ( selection ) {
582582 // Find the common ancestor for all selection's ranges.
583583 let element = Array . from ( selection . getRanges ( ) )
584- . reduce ( ( node , range ) => {
585- if ( ! node ) {
586- return range . getCommonAncestor ( ) ;
584+ . reduce ( ( element , range ) => {
585+ const rangeCommonAncestor = range . getCommonAncestor ( ) ;
586+
587+ if ( ! element ) {
588+ return rangeCommonAncestor ;
587589 }
588590
589- return node . getCommonAncestor ( range . getCommonAncestor ( ) ) ;
591+ return element . getCommonAncestor ( rangeCommonAncestor , { includeSelf : true } ) ;
590592 } , null ) ;
591593
592594 while ( ! this . isLimit ( element ) ) {
Original file line number Diff line number Diff line change @@ -933,6 +933,38 @@ describe( 'Schema', () => {
933933
934934 expect ( schema . getLimitElement ( doc . selection ) ) . to . equal ( root ) ;
935935 } ) ;
936+
937+ it ( 'works fine with multi-range selections if the first range has the root element as a limit element' , ( ) => {
938+ setData (
939+ model ,
940+ '<image>' +
941+ '<caption>[Foo</caption>' +
942+ '</image>' +
943+ '<article>' +
944+ '<paragraph>Paragraph in article]</paragraph>' +
945+ '</article>' +
946+ '<paragraph>Paragraph item 1</paragraph>' +
947+ '<paragraph>Paragraph [item 2]</paragraph>'
948+ ) ;
949+
950+ expect ( schema . getLimitElement ( doc . selection ) ) . to . equal ( root ) ;
951+ } ) ;
952+
953+ it ( 'works fine with multi-range selections if the last range has the root element as a limit element' , ( ) => {
954+ setData (
955+ model ,
956+ '<paragraph>Paragraph item 1</paragraph>' +
957+ '<paragraph>Paragraph [item 2]</paragraph>' +
958+ '<image>' +
959+ '<caption>[Foo</caption>' +
960+ '</image>' +
961+ '<article>' +
962+ '<paragraph>Paragraph in article]</paragraph>' +
963+ '</article>'
964+ ) ;
965+
966+ expect ( schema . getLimitElement ( doc . selection ) ) . to . equal ( root ) ;
967+ } ) ;
936968 } ) ;
937969
938970 describe ( 'checkAttributeInSelection()' , ( ) => {
You can’t perform that action at this time.
0 commit comments