-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cloneContents
properly return document fragment
#642
Conversation
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.
core/dom/range.js
Outdated
if ( isClone && endNode.type == CKEDITOR.NODE_TEXT && startNode.equals( endNode ) ) { | ||
startNode = range.document.createText( startNode.substring( startOffset, endOffset ) ); | ||
docFrag.append( startNode ); | ||
// #426 We need to handle situation when selection is located at the beginning of node, |
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.
Ticket number should be on the end. You can add one empty line so this description does not mixed up with the previous one.
core/dom/range.js
Outdated
docFrag.append( startNode ); | ||
// #426 We need to handle situation when selection is located at the beginning of node, | ||
// so in selection range start node get type == NODE_ELEMENT instead of NODE_TEXT | ||
// We gain selecion like <b>[foo} bar</b>, instead of <b>{foo} bar</b> |
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.
so range start node is of type NODE_ELEMENT (instead of NODE_TEXT). It happens for selection like <b>[foo} bar</b> instead of <b>{foo} bar</b>.
?
core/dom/range.js
Outdated
|
||
// endNode is always text | ||
endNode = range.document.createText( endNode.substring( startOffset, endOffset ) ); | ||
docFrag.append( endNode ); |
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.
Is endNode
used somewhere else? Maybe you could use
docFrag.append( range.document.createText( endNode.substring( startOffset, endOffset ) ) );
I know this is the way the former code was formatted, but assigning new result to endNode
- especially if it is not used any further may look somehow confusing.
|
||
// Variety of edge test cases with selection range in text and elements nodes inside one element and multiple ones (#426). | ||
'test cloneContents - inner selection1': function() { | ||
this.assertHtmlFragment( this.editors.classic, '<p>foo <strong>[bar} baz</strong> foo</p>', 'bar' ); |
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.
Since we check cases with selection on element boundaries, you may consider extending tests with cases like:
<p><strong>
(no text between p and strong - same with text after strong),<p>foo[<strong><u>bar</> ba}z
(some nested elements),<tr><td><strong>...
(many levels of nested tags).
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.
tests was added at the end.
var editor = CKEDITOR.replace( 'editor1' ); | ||
|
||
document.getElementById( 'getFragment' ).onclick = function() { | ||
// debugger; |
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.
Please do not leave commented code like this.
@bender-ui: collapsed | ||
@bender-ckeditor-plugins: divarea, toolbar, basicstyles | ||
|
||
1. Make selection of **bar** word |
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.
Select bar.
?
@bender-ckeditor-plugins: divarea, toolbar, basicstyles | ||
|
||
1. Make selection of **bar** word | ||
1. Press button below editor |
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 .
on the sentence end.
@msamsel There are some differences how selection works in Safari which might be the issue here. When you have selection like |
I think I run unit tests with some local changes so I have to recheck it. |
I rechecked test, Edge/IE11 is fine, however Safari still fails (updated the comment). |
I also run those added unit test without the fix in a code and there is only on test failing on Chrome, FF, Edge, IE9 - IE11 which is None test is failing on IE8 - you should probably check if the issue is reproducible there, if not we may skip this browser. On Safari 4 mentioned earlier tests still fails without the fix. |
Because IE8 and Safari handling a little bit differently with selection than other browser, so I have to ignore part of the tests on those browsers. Generally they kept selection inside specific node, what would be repetition of earlier tests. |
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.
Just 2 small things and we are ready to go.
@@ -557,32 +557,60 @@ | |||
'test cloneContents - inner selection6': function() { | |||
this.assertHtmlFragment( this.editors.classic, '<p>foo <strong>bar {baz]</strong> foo</p>', 'baz' ); | |||
}, | |||
// Safari always keeps selection insdie node. |
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.
Such comments should be right before ignore (so it has a proper context):
'test cloneContents - outer selection1': function() {
// Safari always keeps selection insdie node.
if ( CKEDITOR.env.safari ) {
assert.ignore();
}
this.assertHtmlFragment( this.editors.classic, '<p>foo {<strong>bar] baz</strong> foo</p>', '<strong>bar</strong>' );
},
Same for the one below about IE8 ignore.
Also there is a typo in inside selection insdie node
.
core/dom/range.js
Outdated
endNode.type == CKEDITOR.NODE_TEXT && | ||
( startNode.equals( endNode ) || ( startNode.type === CKEDITOR.NODE_ELEMENT && startNode.getFirst().equals( endNode ) ) ) ) { | ||
|
||
// this should be always text |
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.
Remember about using full sentences like This should be always text.
…ferently select text.
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.
LGTM 👍
What is the purpose of this pull request?
bug fix
Does your PR contain necessary tests?
yep!
This PR contains
What changes did you make?
Modify
if
statement to accept situation when selection start and ends in this same element, butstartNode
has type ofelement
whereendNode
has type oftext
close #426