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

Using RemoveDelta in deleteContent leads to wrong results in collaboration #4195

Closed
scofalik opened this issue Oct 9, 2017 · 3 comments · Fixed by ckeditor/ckeditor5-engine#1163
Assignees
Labels
package:engine type:bug This issue reports a buggy (incorrect) behavior.
Milestone

Comments

@scofalik
Copy link
Contributor

scofalik commented Oct 9, 2017

In deleteContent we make an assumption, that if the merged element is empty, maybe it is better to use batch.remove() instead of merging it.

It is all fine, until you realise that it is incorrect to take action basing on current model state. Here's a counter example:

  1. Editor data is: <p>foo</p><p></p><p>bar</p>.
  2. Second (empty) paragraph is "merged" with first paragraph.
  3. Simultaneously, third paragraph ("bar") is merged with second paragraph.

If second paragraph is removed (instead of merged), then the data from third (merged) paragraph will be "moved" to the second paragraph and removed with it.

@scofalik scofalik self-assigned this Oct 9, 2017
@scofalik
Copy link
Contributor Author

scofalik commented Oct 9, 2017

Alternatively this problem probably could be solved in MergeDelta x RemoveDelta special case transformation -> "if left-side merge element was removed, merge with next left-side element". Although I am not sure if this will make sense in all scenarios.

@scofalik
Copy link
Contributor Author

scofalik commented Oct 9, 2017

Solving this in transformations may be even better, considering this code in deleteContent:

// Removes empty end ancestors:
// <a>fo[o</a><b><a><c>bar]</c></a></b>
// becomes:
// <a>fo[]</a><b><a>{}</a></b>
// So we can remove <a> and <b>.
while ( endPos.parent.isEmpty ) {
	const parentToRemove = endPos.parent;

	endPos = Position.createBefore( parentToRemove );

	batch.remove( parentToRemove );
}

🤔

@scofalik
Copy link
Contributor Author

scofalik commented Oct 10, 2017

Because of https://github.com/ckeditor/ckeditor5-engine/issues/1162#issuecomment-335477136 we cannot introduce this fix in deltas transformations. So I will push the fix with the original idea. Unfortunately, it won't work if empty parents will get removed and I am not really sure whether we should use batch.merge there (see the code snippet in the post above).

We may revisit this problem once again if we drop the deltas idea, as described in the linked issue.

Reinmar referenced this issue in ckeditor/ckeditor5-engine Oct 11, 2017
Fix: The `deleteContent()` algorithm will use merging to "remove" empty element which will ensure a better conflict resolution on collaborative editing. Closes #1161.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 13 milestone Oct 9, 2019
@mlewand mlewand added status:confirmed type:bug This issue reports a buggy (incorrect) behavior. package:engine labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:engine type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants