This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Schema#schema.checkAttributeInSelection() checks attributes of text #1550
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ecbdb2
Schema#schema.checkAttributeInSelection() checks attributes of a text…
f013f46
"Schema#checkAttributeInSelection()" should use current text node or …
989c872
We should check selection attribues instead of text attrs.
42090b1
Add one more test which checks attributes that are set manually.
678fe36
Merge branch 'master' into t/1546
37fe24e
Merge branch 'master' into t/1546
Reinmar d0cd559
Cleaned up the tests. Removed confusing boundary cases with setData()…
Reinmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1047,6 +1047,27 @@ describe( 'Schema', () => { | |
return true; | ||
} | ||
} ); | ||
|
||
schema.addAttributeCheck( ( ctx, attributeName ) => { | ||
// Disallow 'italic' on $text that has attribute 'bold'. | ||
if ( inTextWithBold( ctx ) && attributeName == 'italic' ) { | ||
return false; | ||
} | ||
|
||
// Allow 'italic' on p>$text. | ||
if ( ctx.endsWith( 'p $text' ) && attributeName == 'italic' ) { | ||
return true; | ||
} | ||
|
||
// Allow 'italic' on $root>p. | ||
if ( ctx.endsWith( '$root p' ) && attributeName == 'italic' ) { | ||
return true; | ||
} | ||
|
||
function inTextWithBold( context ) { | ||
return context.endsWith( '$text' ) && context.last.getAttribute( 'bold' ); | ||
} | ||
} ); | ||
} ); | ||
|
||
describe( 'when selection is collapsed', () => { | ||
|
@@ -1062,6 +1083,33 @@ describe( 'Schema', () => { | |
setData( model, '[]' ); | ||
expect( schema.checkAttributeInSelection( doc.selection, attribute ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should check attributes of the selection (selection at the beginning of the text)', () => { | ||
setData( model, '<p><$text bold="true">[]foo</$text></p>' ); | ||
expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false; | ||
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 suspicious... why is it false? What gave the selection the bold attr? I guess |
||
} ); | ||
|
||
it( 'should check attributes of the selection (selection inside the text)', () => { | ||
setData( model, '<p><$text bold="true">f[]oo</$text></p>' ); | ||
expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should check attributes of the selection (selection at the end of the text)', () => { | ||
setData( model, '<p><$text bold="true">foo[]</$text></p>' ); | ||
expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should check attributes of the selection (an attribute sets manually)', () => { | ||
setData( model, '<p>foo[]bar</p>' ); | ||
|
||
expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.true; | ||
|
||
model.change( writer => { | ||
writer.setSelectionAttribute( 'bold', true ); | ||
} ); | ||
|
||
expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false; | ||
} ); | ||
} ); | ||
|
||
describe( 'when selection is not collapsed', () => { | ||
|
@@ -1102,6 +1150,11 @@ describe( 'Schema', () => { | |
setData( model, '[<figure name="figure" title="title"></figure>]' ); | ||
expect( schema.checkAttributeInSelection( doc.selection, 'title' ) ).to.be.true; | ||
} ); | ||
|
||
it( 'should check attributes of text', () => { | ||
setData( model, '<p><$text bold="true">f[o]o</$text></p>' ); | ||
expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false; | ||
} ); | ||
} ); | ||
} ); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing blank line.
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.
Right above there's another addAttributeCheck() call. Why haven't you extended it?