@@ -1710,7 +1710,7 @@ describe( 'DocumentSelection', () => {
1710
1710
} ) ;
1711
1711
1712
1712
describe ( 'MoveOperation to graveyard' , ( ) => {
1713
- it ( 'fix selection range if it ends up in graveyard #1 ' , ( ) => {
1713
+ it ( 'fix selection range if it ends up in graveyard - collapsed selection ' , ( ) => {
1714
1714
selection . _setTo ( new Position ( root , [ 1 , 3 ] ) ) ;
1715
1715
1716
1716
model . applyOperation (
@@ -1725,7 +1725,7 @@ describe( 'DocumentSelection', () => {
1725
1725
expect ( selection . getFirstPosition ( ) . path ) . to . deep . equal ( [ 1 , 2 ] ) ;
1726
1726
} ) ;
1727
1727
1728
- it ( 'fix selection range if it ends up in graveyard #2 ' , ( ) => {
1728
+ it ( 'fix selection range if it ends up in graveyard - text from non-collapsed selection is moved ' , ( ) => {
1729
1729
selection . _setTo ( [ new Range ( new Position ( root , [ 1 , 2 ] ) , new Position ( root , [ 1 , 4 ] ) ) ] ) ;
1730
1730
1731
1731
model . applyOperation (
@@ -1740,7 +1740,7 @@ describe( 'DocumentSelection', () => {
1740
1740
expect ( selection . getFirstPosition ( ) . path ) . to . deep . equal ( [ 1 , 2 ] ) ;
1741
1741
} ) ;
1742
1742
1743
- it ( 'fix selection range if it ends up in graveyard #3 ' , ( ) => {
1743
+ it ( 'fix selection range if it ends up in graveyard - parent of non-collapsed selection is moved ' , ( ) => {
1744
1744
selection . _setTo ( [ new Range ( new Position ( root , [ 1 , 1 ] ) , new Position ( root , [ 1 , 2 ] ) ) ] ) ;
1745
1745
1746
1746
model . applyOperation (
@@ -1755,7 +1755,7 @@ describe( 'DocumentSelection', () => {
1755
1755
expect ( selection . getFirstPosition ( ) . path ) . to . deep . equal ( [ 0 , 6 ] ) ;
1756
1756
} ) ;
1757
1757
1758
- it ( 'fix selection range if it ends up in graveyard #4 - whole content removed' , ( ) => {
1758
+ it ( 'fix selection range if it ends up in graveyard - whole content removed' , ( ) => {
1759
1759
model . applyOperation (
1760
1760
new MoveOperation (
1761
1761
new Position ( root , [ 0 ] ) ,
@@ -1778,6 +1778,63 @@ describe( 'DocumentSelection', () => {
1778
1778
// Now it's clear that it's the default range.
1779
1779
expect ( selection . getFirstPosition ( ) . path ) . to . deep . equal ( [ 0 , 0 ] ) ;
1780
1780
} ) ;
1781
+
1782
+ it ( 'handles multi-range selection in a text node by merging it into one range (resulting in collapsed ranges)' , ( ) => {
1783
+ const ranges = [
1784
+ new Range ( new Position ( root , [ 1 , 1 ] ) , new Position ( root , [ 1 , 2 ] ) ) ,
1785
+ new Range ( new Position ( root , [ 1 , 3 ] ) , new Position ( root , [ 1 , 4 ] ) )
1786
+ ] ;
1787
+
1788
+ selection . _setTo ( ranges ) ;
1789
+
1790
+ model . applyOperation (
1791
+ new MoveOperation (
1792
+ new Position ( root , [ 1 , 1 ] ) ,
1793
+ 4 ,
1794
+ new Position ( doc . graveyard , [ 0 ] ) ,
1795
+ doc . version
1796
+ )
1797
+ ) ;
1798
+
1799
+ expect ( selection . rangeCount ) . to . equal ( 1 ) ;
1800
+ expect ( selection . getFirstPosition ( ) . path ) . to . deep . equal ( [ 1 , 1 ] ) ;
1801
+ expect ( selection . getLastPosition ( ) . path ) . to . deep . equal ( [ 1 , 1 ] ) ;
1802
+ } ) ;
1803
+
1804
+ it ( 'handles multi-range selection on object nodes by merging it into one range (resulting in non-collapsed ranges)' , ( ) => {
1805
+ model . schema . register ( 'outer' , {
1806
+ isObject : true
1807
+ } ) ;
1808
+ model . schema . register ( 'inner' , {
1809
+ isObject : true ,
1810
+ allowIn : 'outer'
1811
+ } ) ;
1812
+
1813
+ root . _removeChildren ( 0 , root . childCount ) ;
1814
+ root . _insertChild ( 0 , [
1815
+ new Element ( 'outer' , [ ] , [ new Element ( 'inner' ) , new Element ( 'inner' ) , new Element ( 'inner' ) ] )
1816
+ ] ) ;
1817
+
1818
+ const ranges = [
1819
+ new Range ( new Position ( root , [ 0 , 0 ] ) , new Position ( root , [ 0 , 1 ] ) ) ,
1820
+ new Range ( new Position ( root , [ 0 , 1 ] ) , new Position ( root , [ 0 , 2 ] ) )
1821
+ ] ;
1822
+
1823
+ selection . _setTo ( ranges ) ;
1824
+
1825
+ model . applyOperation (
1826
+ new MoveOperation (
1827
+ new Position ( root , [ 0 , 0 ] ) ,
1828
+ 2 ,
1829
+ new Position ( doc . graveyard , [ 0 ] ) ,
1830
+ doc . version
1831
+ )
1832
+ ) ;
1833
+
1834
+ expect ( selection . rangeCount ) . to . equal ( 1 ) ;
1835
+ expect ( selection . getFirstPosition ( ) . path ) . to . deep . equal ( [ 0 , 0 ] ) ;
1836
+ expect ( selection . getLastPosition ( ) . path ) . to . deep . equal ( [ 0 , 1 ] ) ;
1837
+ } ) ;
1781
1838
} ) ;
1782
1839
1783
1840
it ( '`DocumentSelection#change:range` event should be fire once even if selection contains multi-ranges' , ( ) => {
0 commit comments