Skip to content
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

Merged
merged 10 commits into from
Jul 28, 2017
Merged

cloneContents properly return document fragment #642

merged 10 commits into from
Jul 28, 2017

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Jul 12, 2017

What is the purpose of this pull request?

bug fix

Does your PR contain necessary tests?

yep!

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

Modify if statement to accept situation when selection start and ends in this same element, but startNode has type of element where endNode has type of text

close #426

@f1ames f1ames self-requested a review July 14, 2017 07:03
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 4 test failing on Safari:
screen shot 2017-07-14 at 12 07 34

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,
Copy link
Contributor

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.

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>
Copy link
Contributor

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>.

?


// endNode is always text
endNode = range.document.createText( endNode.substring( startOffset, endOffset ) );
docFrag.append( endNode );
Copy link
Contributor

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' );
Copy link
Contributor

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).

Copy link
Contributor Author

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;
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

@f1ames
Copy link
Contributor

f1ames commented Jul 14, 2017

@msamsel There are some differences how selection works in Safari which might be the issue here. When you have selection like [<strong>Text</strong>]/<strong>[Text]</strong>, Safari always reports it as <strong>{Text}</strong> - so as attached in text nodes instead of element nodes AFAIR (basically, such selection is always attached in text nodes not element nodes).

@f1ames f1ames self-requested a review July 14, 2017 10:45
@f1ames
Copy link
Contributor

f1ames commented Jul 14, 2017

I think I run unit tests with some local changes so I have to recheck it.

@f1ames
Copy link
Contributor

f1ames commented Jul 14, 2017

I rechecked test, Edge/IE11 is fine, however Safari still fails (updated the comment).

@f1ames
Copy link
Contributor

f1ames commented Jul 14, 2017

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 tests/core/dom/range/clonecontents test cloneContents - inner selection1. Maybe we could reduce the amount of tests or find more failing cases (if there is more than one).

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.

@msamsel
Copy link
Contributor Author

msamsel commented Jul 18, 2017

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.

Copy link
Contributor

@f1ames f1ames left a 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.
Copy link
Contributor

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.

endNode.type == CKEDITOR.NODE_TEXT &&
( startNode.equals( endNode ) || ( startNode.type === CKEDITOR.NODE_ELEMENT && startNode.getFirst().equals( endNode ) ) ) ) {

// this should be always text
Copy link
Contributor

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.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@f1ames f1ames merged commit 5655252 into master Jul 28, 2017
@f1ames f1ames deleted the t/426 branch July 28, 2017 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants