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
T/1063: Introduce Selection#isEntireContentSelected( element )
#1064
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -624,6 +624,20 @@ export default class Selection { | |
} | ||
} | ||
|
||
/** | ||
* Checks whether the entire content in specified element is selected. | ||
* | ||
* @param {module:engine/model/element~Element} element | ||
* @returns {Boolean} | ||
*/ | ||
isEntireContentSelected( element ) { | ||
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 element should default to the root of the selection's root ( |
||
const limitStartPosition = Position.createAt( element ); | ||
const limitEndPosition = Position.createAt( element, 'end' ); | ||
|
||
return limitStartPosition.isTouching( this.getFirstPosition() ) && | ||
limitEndPosition.isTouching( this.getLastPosition() ); | ||
} | ||
|
||
/** | ||
* Creates and returns an instance of `Selection` that is a clone of given selection, meaning that it has same | ||
* ranges and same direction as this selection. | ||
|
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 |
---|---|---|
|
@@ -1237,4 +1237,56 @@ describe( 'Selection', () => { | |
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'isEntireContentSelected()', () => { | ||
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. Missing tests:
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. Added in 9ee9e12. |
||
beforeEach( () => { | ||
doc.schema.registerItem( 'p', '$block' ); | ||
doc.schema.allow( { name: 'p', inside: '$root' } ); | ||
} ); | ||
|
||
it( 'returns true if the entire content in $root is selected', () => { | ||
setData( doc, '<p>[Foo</p><p>Bom</p><p>Bar]</p>' ); | ||
|
||
const root = doc.getRoot(); | ||
|
||
expect( doc.selection.isEntireContentSelected( root ) ).to.equal( true ); | ||
} ); | ||
|
||
it( 'returns false when only a fragment of the content in $root is selected', () => { | ||
setData( doc, '<p>Fo[o</p><p>Bom</p><p>Bar]</p>' ); | ||
|
||
const root = doc.getRoot(); | ||
|
||
expect( doc.selection.isEntireContentSelected( root ) ).to.equal( false ); | ||
} ); | ||
|
||
it( 'returns true if the entire content in specified element is selected', () => { | ||
setData( doc, '<p>Foo</p><p>[Bom]</p><p>Bar</p>' ); | ||
|
||
const root = doc.getRoot(); | ||
const secondParagraph = root.getNodeByPath( [ 1 ] ); | ||
|
||
expect( doc.selection.isEntireContentSelected( secondParagraph ) ).to.equal( true ); | ||
} ); | ||
|
||
it( 'returns false if the entire content in specified element is not selected', () => { | ||
setData( doc, '<p>Foo</p><p>[Bom</p><p>B]ar</p>' ); | ||
|
||
const root = doc.getRoot(); | ||
const secondParagraph = root.getNodeByPath( [ 1 ] ); | ||
|
||
expect( doc.selection.isEntireContentSelected( secondParagraph ) ).to.equal( false ); | ||
} ); | ||
|
||
it( 'returns false when the entire content except an empty element is selected', () => { | ||
doc.schema.registerItem( 'img', '$inline' ); | ||
doc.schema.allow( { name: 'img', inside: 'p' } ); | ||
|
||
setData( doc, '<p><img></img>[Foo]</p>' ); | ||
|
||
const root = doc.getRoot(); | ||
|
||
expect( doc.selection.isEntireContentSelected( root ) ).to.equal( 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.
This description is not accurate. In such case, the
<b>
's content is also fully selected:It's hard to explain this in just one paragraph, but we should try with something like:
Checks whether the selection contains the entire content of the given element. This means that selection must start at a position {@link module:engine/model/position~Position#isTouching touching} the element's start and ends at position touching the element's end.