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

The findOptimalInsertionPosition() should use getTopMostBlocks() instead getSelectedBlocks() #4609

Closed
jodator opened this issue Jul 23, 2019 · 4 comments · Fixed by ckeditor/ckeditor5-engine#1770
Assignees
Labels
package:widget type:bug This issue reports a buggy (incorrect) behavior.

Comments

@jodator
Copy link
Contributor

jodator commented Jul 23, 2019

I'm still battling with a more generic issue but it seems that selection.getSelectedBlocks() is causing some problems (https://github.com/ckeditor/ckeditor5-indent/issues/11, https://github.com/ckeditor/ckeditor5-table/issues/126 and the latest: https://github.com/ckeditor/ckeditor5-table/issues/199).

Generally speaking the below use of this method:

const firstBlockInSelection = model.selection.getSelectedBlocks().next().value

in most cases will return the first block but in case of tables it will return first inner child of a parent block and the table.

So if a selection contains a table and a heading it will return:

["paragraph", "paragraph", "paragraph", "paragraph", "table", "heading1"]

For some algorithms (most?) we want to have top-most blocks (so the selection.getTopMostBlocks() should be used. Which would return only:

["table", "heading1"]

@Reinmar I didn't dig much into it looks like most similar issues are related to that algorithm so either:

  1. The selection.getSelectedBlocks() should return parent first
  2. (preferable) We should use selection.getTopMostBlocks() rather than selection.getSelectedBlocks().
@jodator jodator changed the title The findOptimalInsertionPosition should use getTopMostBlocks() instead getSelectedBlocks() The findOptimalInsertionPosition() should use getTopMostBlocks() instead getSelectedBlocks() Jul 23, 2019
@jodator jodator transferred this issue from ckeditor/ckeditor5-engine Jul 23, 2019
@jodator
Copy link
Contributor Author

jodator commented Jul 23, 2019

ps.: Changing the selection.getSelectedBlocks() to selection.getTopMostBlocks() does fix the issue in tables (ckeditor/ckeditor5-table#199) and does not break the tests so it might be quick fix.

@jodator jodator self-assigned this Jul 23, 2019
@Reinmar
Copy link
Member

Reinmar commented Jul 24, 2019

Haha :D Check out the history and timing of this issue: https://github.com/ckeditor/ckeditor5-engine/issues/826

@Reinmar
Copy link
Member

Reinmar commented Jul 24, 2019

I didn't know that we introduced getTopMostBlocks() and unfortunately I think it was wrong. For two reasons:

  • The role of getSelectedBlocks() was to be useful in those cases. It was introduced to be used in those features because most of them work in the same way. If we now see that most of them need to work differently than the current implementation of getSelectedBlocks() then, IMO, we should be tuning the original method for that.
  • If we see use cases for returning all blocks inside the selection (even nested ones), then I think this should be a param of the original method.

cc @scofalik

@Reinmar
Copy link
Member

Reinmar commented Jul 24, 2019

@scofalik shares the same sentiments. Block quote may be a use case for the current behaviour of getSelectedBlocks() so most likely we need to keep it. It also makes sense to not remove a functionality that we had. But we can make it a non-default one, the default being the top most blocks.

@jodator
Copy link
Contributor Author

jodator commented Jul 30, 2019

I couldn't find any feature that uses that deep structure, to be honest. The block quote feature actually uses the getTopMostBlocks() now.

After renaming getTopMostBlocks() to getSelectedBlocks() and removing the latter everything passes except for the tests for getSelectedBlocks()... I'm not sure if this is used anywhere.

Reinmar referenced this issue in ckeditor/ckeditor5-engine Sep 3, 2019
Other: Remove the `Selection#getTopMostBlocks()` method. Closes ckeditor/ckeditor5-widget#95. Closes ckeditor/ckeditor5-table#199.

BREAKING CHANGE: The `Selection#getTopMostBlocks()` was removed from the public API. Use `Selection#getSelectedBlocks()` instead.

BREAKING CHANGE: The `Selection#getSelectedBlocks()` does not return blocks nested in other blocks now.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-widget Oct 9, 2019
@mlewand mlewand added this to the iteration 27 milestone Oct 9, 2019
@mlewand mlewand added type:bug This issue reports a buggy (incorrect) behavior. package:widget labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:widget type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants