Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Mark nested widgets properly #58

Merged
merged 1 commit into from
Nov 19, 2018
Merged

Mark nested widgets properly #58

merged 1 commit into from
Nov 19, 2018

Conversation

pomek
Copy link
Member

@pomek pomek commented Nov 15, 2018

Suggested merge commit message (convention)

Fix: Selection converter will mark nested widgets properly. Closes ckeditor/ckeditor5#4594.

@pomek
Copy link
Member Author

pomek commented Nov 15, 2018

The code became ugly there and needs refactoring (and tests of course), but the change seems to fix the issue.

I moved a part of the logic to the separate method. Unfortunately, I have no idea how I could more improve the code. Any tip will be appreciated.

@coveralls
Copy link

coveralls commented Nov 15, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling cf06c9f on t/57 into 49afa6e on master.

@@ -1210,5 +1210,74 @@ describe( 'Widget', () => {

expect( getModelData( model ) ).to.equal( '<paragraph>bar</paragraph>[<widget></widget>]<paragraph>foo</paragraph>' );
} );

it( 'should select the most top-outer widget if widgets are nested', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Missing scenarios:

  • multiple widgets (on the same level) in the selection,
  • some additional element between the outer and nested widget (widget > container > widget)

src/widget.js Outdated
for ( const value of range ) {
const node = value.item;

if ( node.is( 'element' ) && isWidget( node ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

As I commented, this code was just an ugly quick fix. I didn't mean the fact that it was defined in that listener – moving this code to a method doesn't change much (in fact, I'd revert this change – less code, less documentation). What I meant by "it needs refactoring" is that I added a nested if() for no good reason – you can flatten this and extract the condition to a helper function. Also, I think we could use the last element from previouslySelected if it was an array (although, I have mixed feeling about such change). Plus, the added condition requires a comment because Array.from( node.getAncestors() ).includes( lastMarked ) is hardly idiomatic.

@pomek
Copy link
Member Author

pomek commented Nov 16, 2018

Ready to review once again.

src/utils.js Outdated
* @param {module:engine/view/element~Element|null} parent A parent for the element.
* @returns {Boolean}
*/
export function isChild( element, parent ) {
Copy link
Member

Choose a reason for hiding this comment

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

This util makes no sense in this place. This file contains widget utils. You added a general one.

See also https://github.com/ckeditor/ckeditor5-engine/issues/1588.

Please make this a private util of src/widget.js and add a comment under https://github.com/ckeditor/ckeditor5-engine/issues/1588 that it should be fixed.

Copy link
Member

@Reinmar Reinmar left a comment

Choose a reason for hiding this comment

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

As commented.

@pomek
Copy link
Member Author

pomek commented Nov 19, 2018

@Reinmar, fixed.

@Reinmar Reinmar merged commit a78efec into master Nov 19, 2018
@Reinmar Reinmar deleted the t/57 branch November 19, 2018 13:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Selection converter should mark the top-most widget only
3 participants