-
Notifications
You must be signed in to change notification settings - Fork 40
T/1436: Fixing selection that cross limit node boundaries. #1450
Changes from 6 commits
8be680d
de7ab75
93b927d
c744608
4b381bf
f16620d
8ea5fb5
6060d76
a7b40b7
9a84bb2
f5bffd4
2445ef2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -494,9 +494,9 @@ describe( 'downcast-selection-converters', () => { | |
|
||
describe( 'table cell selection converter', () => { | ||
beforeEach( () => { | ||
model.schema.register( 'table' ); | ||
model.schema.register( 'tr' ); | ||
model.schema.register( 'td' ); | ||
model.schema.register( 'table', { isLimit: true } ); | ||
model.schema.register( 'tr', { isLimit: true } ); | ||
model.schema.register( 'td', { isLimit: true } ); | ||
|
||
model.schema.extend( 'table', { allowIn: '$root' } ); | ||
model.schema.extend( 'tr', { allowIn: 'table' } ); | ||
|
@@ -519,16 +519,16 @@ describe( 'downcast-selection-converters', () => { | |
} | ||
|
||
for ( const range of selection.getRanges() ) { | ||
const node = range.start.nodeAfter; | ||
const node = range.start.parent; | ||
|
||
if ( node == range.end.nodeBefore && node instanceof ModelElement && node.name == 'td' ) { | ||
if ( node instanceof ModelElement && node.name == 'td' ) { | ||
conversionApi.consumable.consume( selection, 'selection' ); | ||
|
||
const viewNode = conversionApi.mapper.toViewElement( node ); | ||
conversionApi.writer.addClass( 'selected', viewNode ); | ||
} | ||
} | ||
} ); | ||
}, { priority: 'high' } ); | ||
} ); | ||
|
||
it( 'should not be used to convert selection that is not on table cell', () => { | ||
|
@@ -542,7 +542,7 @@ describe( 'downcast-selection-converters', () => { | |
it( 'should add a class to the selected table cell', () => { | ||
test( | ||
// table tr#0 |td#0, table tr#0 td#0| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the comments up to date now? |
||
[ [ 0, 0, 0 ], [ 0, 0, 1 ] ], | ||
[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 3 ] ], | ||
'<table><tr><td>foo</td></tr><tr><td>bar</td></tr></table>', | ||
'<table><tr><td class="selected">foo</td></tr><tr><td>bar</td></tr></table>' | ||
); | ||
|
@@ -551,9 +551,9 @@ describe( 'downcast-selection-converters', () => { | |
it( 'should not be used if selection contains more than just a table cell', () => { | ||
test( | ||
// table tr td#1, table tr#2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here too? |
||
[ [ 0, 0, 0, 1 ], [ 0, 0, 2 ] ], | ||
[ [ 0, 0, 0, 1 ], [ 0, 0, 1, 3 ] ], | ||
'<table><tr><td>foo</td><td>bar</td></tr></table>', | ||
'<table><tr><td>f{oo</td><td>bar</td>]</tr></table>' | ||
'[<table><tr><td>foo</td><td>bar</td></tr></table>]' | ||
); | ||
} ); | ||
} ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import Position from '../../src/model/position'; | |
import Range from '../../src/model/range'; | ||
import Selection from '../../src/model/selection'; | ||
|
||
import { setData, getData, stringify } from '../../src/dev-utils/model'; | ||
import { getData, setData, stringify } from '../../src/dev-utils/model'; | ||
|
||
import AttributeDelta from '../../src/model/delta/attributedelta'; | ||
|
||
|
@@ -983,6 +983,28 @@ describe( 'Schema', () => { | |
|
||
expect( schema.getLimitElement( doc.selection ) ).to.equal( root ); | ||
} ); | ||
|
||
it( 'accepts range as an argument', () => { | ||
schema.extend( 'article', { isLimit: true } ); | ||
schema.extend( 'section', { isLimit: true } ); | ||
|
||
setData( model, '<div><section><article><paragraph>foo[]bar</paragraph></article></section></div>' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you set a selection anywhere if you're testing if this method works with a range? You can use |
||
|
||
const article = root.getNodeByPath( [ 0, 0, 0 ] ); | ||
|
||
expect( schema.getLimitElement( new Range( new Position( root, [ 0, 0, 0, 0, 2 ] ) ) ) ).to.equal( article ); | ||
} ); | ||
|
||
it( 'accepts position as an argument', () => { | ||
schema.extend( 'article', { isLimit: true } ); | ||
schema.extend( 'section', { isLimit: true } ); | ||
|
||
setData( model, '<div><section><article><paragraph>foo[]bar</paragraph></article></section></div>' ); | ||
|
||
const article = root.getNodeByPath( [ 0, 0, 0 ] ); | ||
|
||
expect( schema.getLimitElement( new Position( root, [ 0, 0, 0, 0, 2 ] ) ) ).to.equal( article ); | ||
} ); | ||
} ); | ||
|
||
describe( 'checkAttributeInSelection()', () => { | ||
|
@@ -1101,7 +1123,13 @@ describe( 'Schema', () => { | |
} | ||
} ); | ||
|
||
setData( model, '<p>foo<img />bar</p>' ); | ||
// Parse data string to model. | ||
const parsedResult = setData._parse( '[<p>foo<img />bar</p>]', model.schema, { context: [ root.name ] } ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the public export. |
||
|
||
// Set parsed model data to prevent selection post-fixer from running. | ||
model.change( writer => { | ||
writer.insert( parsedResult.model, root ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure you need to insert that into the model. Perhaps it works without that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really know how to do that - AFAICS it's easiest to just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method we're testing there OTOH, we can leave it with the |
||
} ); | ||
|
||
ranges = [ Range.createOn( root.getChild( 0 ) ) ]; | ||
} ); | ||
|
@@ -1123,12 +1151,12 @@ describe( 'Schema', () => { | |
schema.extend( 'img', { allowAttributes: 'bold' } ); | ||
schema.extend( '$text', { allowIn: 'img' } ); | ||
|
||
setData( model, '[<p>foo<img>xxx</img>bar</p>]' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes the semantics of this test. Let's better use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still not resolved. |
||
setData( model, '<p>[foo<img>xxx</img>bar]</p>' ); | ||
|
||
const validRanges = schema.getValidRanges( doc.selection.getRanges(), attribute ); | ||
const sel = new Selection( validRanges ); | ||
|
||
expect( stringify( root, sel ) ).to.equal( '[<p>foo<img>]xxx[</img>bar</p>]' ); | ||
expect( stringify( root, sel ) ).to.equal( '<p>[foo<img>]xxx[</img>bar]</p>' ); | ||
} ); | ||
|
||
it( 'should return three ranges when attribute is not allowed on one element but is allowed on its child', () => { | ||
|
@@ -1141,12 +1169,12 @@ describe( 'Schema', () => { | |
} | ||
} ); | ||
|
||
setData( model, '[<p>foo<img>xxx</img>bar</p>]' ); | ||
setData( model, '<p>[foo<img>xxx</img>bar]</p>' ); | ||
|
||
const validRanges = schema.getValidRanges( doc.selection.getRanges(), attribute ); | ||
const sel = new Selection( validRanges ); | ||
|
||
expect( stringify( root, sel ) ).to.equal( '[<p>foo]<img>[xxx]</img>[bar</p>]' ); | ||
expect( stringify( root, sel ) ).to.equal( '<p>[foo]<img>[xxx]</img>[bar]</p>' ); | ||
} ); | ||
|
||
it( 'should not leak beyond the given ranges', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -562,7 +562,7 @@ describe( 'DataController utils', () => { | |
schema.register( 'image', { allowWhere: '$text' } ); | ||
schema.register( 'paragraph', { inheritAllFrom: '$block' } ); | ||
schema.register( 'heading1', { inheritAllFrom: '$block' } ); | ||
schema.register( 'blockWidget' ); | ||
schema.register( 'blockWidget', { isLimit: true } ); | ||
schema.register( 'restrictedRoot', { | ||
isLimit: true | ||
} ); | ||
|
@@ -621,7 +621,7 @@ describe( 'DataController utils', () => { | |
deleteContent( model, selection ); | ||
|
||
expect( getData( model, { rootName: 'bodyRoot' } ) ) | ||
.to.equal( '[<paragraph>x</paragraph>]<paragraph></paragraph><paragraph>z</paragraph>' ); | ||
.to.equal( '<paragraph>[x]</paragraph><paragraph></paragraph><paragraph>z</paragraph>' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can change the initial selection too, so this test is less confusing (we're not checking the sel post-fixer here). |
||
} ); | ||
|
||
it( 'creates a paragraph when text is not allowed (block widget selected)', () => { | ||
|
@@ -644,7 +644,16 @@ describe( 'DataController utils', () => { | |
{ rootName: 'bodyRoot' } | ||
); | ||
|
||
deleteContent( model, doc.selection ); | ||
model.change( writer => { | ||
// Set selection to[<heading1>yyy</heading1>] in change() block due to selection post-fixer. | ||
const range = new Range( | ||
new Position( doc.getRoot( 'bodyRoot' ), [ 1 ] ), | ||
new Position( doc.getRoot( 'bodyRoot' ), [ 2 ] ) | ||
); | ||
writer.setSelection( range ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't have to set that selection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it'd be good if you changed it in the |
||
|
||
deleteContent( model, doc.selection ); | ||
} ); | ||
|
||
expect( getData( model, { rootName: 'bodyRoot' } ) ) | ||
.to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' ); | ||
|
@@ -657,7 +666,16 @@ describe( 'DataController utils', () => { | |
{ rootName: 'bodyRoot' } | ||
); | ||
|
||
deleteContent( model, doc.selection ); | ||
model.change( writer => { | ||
// Set selection to[<heading1>yyy</heading1><paragraph>yyy</paragraph>] in change() block due to selection post-fixer. | ||
const range = new Range( | ||
new Position( doc.getRoot( 'bodyRoot' ), [ 1 ] ), | ||
new Position( doc.getRoot( 'bodyRoot' ), [ 3 ] ) | ||
); | ||
writer.setSelection( range ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above– no need to set it. Also, it'd be good if you changed it in the |
||
|
||
deleteContent( model, doc.selection ); | ||
} ); | ||
|
||
expect( getData( model, { rootName: 'bodyRoot' } ) ) | ||
.to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to update the type.