@@ -1117,6 +1117,20 @@ describe( 'Selection', () => {
1117
1117
) ;
1118
1118
} ) ;
1119
1119
1120
+ it ( 'does not go beyond limit elements' , ( ) => {
1121
+ model . schema . register ( 'table' , { isBlock : true , isLimit : true , isObject : true , allowIn : '$root' } ) ;
1122
+ model . schema . register ( 'tableRow' , { allowIn : 'table' , isLimit : true } ) ;
1123
+ model . schema . register ( 'tableCell' , { allowIn : 'tableRow' , isObject : true } ) ;
1124
+
1125
+ model . schema . register ( 'blk' , { allowIn : [ '$root' , 'tableCell' ] , isObject : true , isBlock : true } ) ;
1126
+
1127
+ model . schema . extend ( 'p' , { allowIn : 'tableCell' } ) ;
1128
+
1129
+ setData ( model , '<table><tableRow><tableCell><p>foo</p>[<blk></blk><p>bar]</p></tableCell></tableRow></table>' ) ;
1130
+
1131
+ expect ( stringifyBlocks ( doc . selection . getTopMostBlocks ( ) ) ) . to . deep . equal ( [ 'blk' , 'p#bar' ] ) ;
1132
+ } ) ;
1133
+
1120
1134
// Map all elements to data of its first child text node.
1121
1135
function toText ( elements ) {
1122
1136
return Array . from ( elements ) . map ( el => {
@@ -1128,11 +1142,11 @@ describe( 'Selection', () => {
1128
1142
describe ( 'getTopMostBlocks()' , ( ) => {
1129
1143
beforeEach ( ( ) => {
1130
1144
model . schema . register ( 'p' , { inheritAllFrom : '$block' } ) ;
1131
- model . schema . register ( 'lvl0 ' , { isBlock : true , isLimit : true , isObject : true , allowIn : '$root' } ) ;
1132
- model . schema . register ( 'lvl1 ' , { allowIn : 'lvl0 ' , isLimit : true } ) ;
1133
- model . schema . register ( 'lvl2 ' , { allowIn : 'lvl1 ' , isObject : true } ) ;
1145
+ model . schema . register ( 'table ' , { isBlock : true , isLimit : true , isObject : true , allowIn : '$root' } ) ;
1146
+ model . schema . register ( 'tableRow ' , { allowIn : 'table ' , isLimit : true } ) ;
1147
+ model . schema . register ( 'tableCell ' , { allowIn : 'tableRow ' , isObject : true } ) ;
1134
1148
1135
- model . schema . extend ( 'p' , { allowIn : 'lvl2 ' } ) ;
1149
+ model . schema . extend ( 'p' , { allowIn : 'tableCell ' } ) ;
1136
1150
} ) ;
1137
1151
1138
1152
it ( 'returns an iterator' , ( ) => {
@@ -1169,28 +1183,24 @@ describe( 'Selection', () => {
1169
1183
} ) ;
1170
1184
1171
1185
it ( 'returns only top most blocks' , ( ) => {
1172
- setData ( model , '[<p>foo</p><lvl0><lvl1><lvl2 ><p>bar</p></lvl2 ></lvl1 ></lvl0 ><p>baz</p>]' ) ;
1186
+ setData ( model , '[<p>foo</p><table><tableRow><tableCell ><p>bar</p></tableCell ></tableRow ></table ><p>baz</p>]' ) ;
1173
1187
1174
- expect ( stringifyBlocks ( doc . selection . getTopMostBlocks ( ) ) ) . to . deep . equal ( [ 'p#foo' , 'lvl0 ' , 'p#baz' ] ) ;
1188
+ expect ( stringifyBlocks ( doc . selection . getTopMostBlocks ( ) ) ) . to . deep . equal ( [ 'p#foo' , 'table ' , 'p#baz' ] ) ;
1175
1189
} ) ;
1176
1190
1177
1191
it ( 'returns only selected blocks even if nested in other blocks' , ( ) => {
1178
- setData ( model , '<p>foo</p><lvl0><lvl1><lvl2 ><p>[b]ar</p></lvl2 ></lvl1 ></lvl0 ><p>baz</p>' ) ;
1192
+ setData ( model , '<p>foo</p><table><tableRow><tableCell ><p>[b]ar</p></tableCell ></tableRow ></table ><p>baz</p>' ) ;
1179
1193
1180
1194
expect ( stringifyBlocks ( doc . selection . getTopMostBlocks ( ) ) ) . to . deep . equal ( [ 'p#bar' ] ) ;
1181
1195
} ) ;
1182
1196
1183
- // Map all elements to names. If element contains child text node it will be appended to name with '#'.
1184
- function stringifyBlocks ( elements ) {
1185
- return Array . from ( elements ) . map ( el => {
1186
- const name = el . name ;
1197
+ it ( 'returns only selected blocks even if nested in other blocks (selection on the block)' , ( ) => {
1198
+ model . schema . register ( 'blk' , { allowIn : [ '$root' , 'tableCell' ] , isObject : true , isBlock : true } ) ;
1187
1199
1188
- const firstChild = el . getChild ( 0 ) ;
1189
- const hasText = firstChild && firstChild . data ;
1200
+ setData ( model , '<table><tableRow><tableCell><p>foo</p>[<blk></blk><p>bar]</p></tableCell></tableRow></table>' ) ;
1190
1201
1191
- return hasText ? `${ name } #${ firstChild . data } ` : name ;
1192
- } ) ;
1193
- }
1202
+ expect ( stringifyBlocks ( doc . selection . getTopMostBlocks ( ) ) ) . to . deep . equal ( [ 'blk' , 'p#bar' ] ) ;
1203
+ } ) ;
1194
1204
} ) ;
1195
1205
1196
1206
describe ( 'attributes interface' , ( ) => {
@@ -1366,4 +1376,16 @@ describe( 'Selection', () => {
1366
1376
expect ( doc . selection . containsEntireContent ( ) ) . to . equal ( false ) ;
1367
1377
} ) ;
1368
1378
} ) ;
1379
+
1380
+ // Map all elements to names. If element contains child text node it will be appended to name with '#'.
1381
+ function stringifyBlocks ( elements ) {
1382
+ return Array . from ( elements ) . map ( el => {
1383
+ const name = el . name ;
1384
+
1385
+ const firstChild = el . getChild ( 0 ) ;
1386
+ const hasText = firstChild && firstChild . data ;
1387
+
1388
+ return hasText ? `${ name } #${ firstChild . data } ` : name ;
1389
+ } ) ;
1390
+ }
1369
1391
} ) ;
0 commit comments