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

Fix for wrong deletion of mixed text and table content #1882

Closed
wants to merge 11 commits into from
Closed

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Apr 10, 2018

What is the purpose of this pull request?

Bug fix

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

Close #541

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

The fix is working, but is not coherent with native Firefox behavior. Firefox, in case of the second table, move text from/into table:
Firefox moving selection after pressing Backspace/Delete

Not to mention IE/Edge that does not do anything at all ¯_(ツ)_/¯

There is also one more problem: failing test after the changes → http://tests.ckeditor.test:1030/tests/core/editable/keystrokes/keystrokes#tests%2Fcore%2Feditable%2Fkeystrokes%2Fkeystrokes%20test%20handle%20del%20with%20full%20table%20content%20selected

There is also one thing that makes me wonder: why didn't we use editor.extractSelectedHtml at first place? 🤔

core/editable.js Outdated
@@ -2528,47 +2528,25 @@
endPath = range.endPath(),
endBlock = endPath.block;

// Selection must be anchored in two different blocks.
if ( !startBlock || !endBlock || startBlock.equals( endBlock ) )
var selectionInTwoDifferentBlocks = !startBlock || !endBlock || startBlock.equals( endBlock );
Copy link
Member

Choose a reason for hiding this comment

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

I'm quite sure that when startBlock equals endBlock, then selection is contained inside one block.

core/editable.js Outdated

// Selection must be anchored in two different blocks
// Boundary block is not in table (block elements are empty there).
if ( selectionInTwoDifferentBlocks && !hasBoundariesInTable ) {
Copy link
Member

Choose a reason for hiding this comment

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

The comment condradicts the code. false is returned if selectionInTwoDifferentBlocks is true, while comment stands the opposite.

core/editable.js Outdated

editor.fire( 'saveSnapshot' );

// Remove bogus to avoid duplicated boguses.
var bogus;
if ( ( bogus = startBlock.getBogus() ) )
if ( ( bogus = startBlock && startBlock.getBogus() ) )
Copy link
Member

Choose a reason for hiding this comment

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

That line of code became ugly. Let's separate if from variable declaration.

@mlewand
Copy link
Contributor

mlewand commented Apr 24, 2018

Firefox

I had a look with @msamsel during a f2f talk and the Firefox thing looks clearly like their feature (if you have selected same element on both ends, here paragraph, and delete the content then merge it). We should not worry about that at this point.

Edge / IE

As of Edge it is clearly an upstream issue in Edge/IE. Normally I'd say that all we need to do here is report upstream issue and not worry about it, but it will look kind of silly if we say in changelog that we fixed this case, but it does not work in Edge / IE.

With above in mind, please:

  • Create a feature request to add handling for IE / Edge.
  • Report an upstream issue, and link it properly.

So this PR should not worry about IE/Edge support, that will be done in a follow-up PR.

@msamsel
Copy link
Contributor Author

msamsel commented Apr 24, 2018

There is also one thing that makes me wonder: why didn't we use editor.extractSelectedHtml at first place?

I think because editor.extractSelectedHtml was developed 3 years ago, and this corrected part was developed 4 years ago ;P

Edge case was extracted to: #1919
Firefox was reported as inconsistent behaviour https://bugzilla.mozilla.org/show_bug.cgi?id=1456427

Please also remember that main point of this fix was to prevent of removing entire table cells from tables and inserting <p> tags under <tr> instead of <td> in WebKits browsers. Jumping content from paragraph to table cell and vice versa are different case and wasn't covered in issue description.

Another thing is correct behaviour. Jumping content from paragraph below table to its cell seems to be inappropriate. That's why paragraphs remain under table.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Seems like defining correct behavior is not trivial… I've create native [contenteditable] demo, which shows following things:

Chrome/Safari

  1. When deleting from the beginning of the table, content outside the table is not merged with the content from the table.
  2. When deleting from the end of the table, content outside is merged.
  3. When overwriting with some letter, the content is merged for selection at the end of the table.

Firefox

  1. When deleting from table without paragraphs, content outside the table is not merged into it.
  2. When deleting from table with paragraphs, content outside the table is merged into it.
  3. When overwriting with some letter, the content is merged in the second table.

So even in Chrome/Safari we end up with inconsistent behavior, as disallowing merge after deleting has totally different behavior than overwriting with new content. IMO it's an issue that should be addressed.

@msamsel
Copy link
Contributor Author

msamsel commented Apr 30, 2018

@mlewand could you provide feedback what behaviour should be implemented in CKE4?

@mlewand
Copy link
Contributor

mlewand commented Apr 30, 2018

@msamsel @Comandeer There's nothing wrong with unifying the results across the browser.

When deleting from the beginning of the table, content outside the table is not merged with the content from the table.

What is exactly the issue? I have used delbackspacequirks/manual/tables to repro it an Chrome, and it works the same for me in both cases.


When deleting from the end of the table, content outside is merged.

I find it to be a positive change not to merge the content in that case.


When overwriting with some letter, the content is merged for selection at the end of the table.

Same as above.


As for Firefox points, is the original issue related to Firefox? Or is the current PR changing Firefox behavior anyhow?

@mlewand
Copy link
Contributor

mlewand commented May 7, 2018

Note that you could also give a try with document.execCommand approach, e.g. document.execComand( 'delete' ). Although, for me, it should be exact sam logic as pressing the delete key, after brief checking it looks like Chrome implements actually a different logic there.

@mlewand
Copy link
Contributor

mlewand commented May 7, 2018

After f2f talk with @msamsel seems that delete command looks promising, the problem is that range.scrollIntoView() breaks the selection if anchored in a text (thus #1956). @msamsel as for fighting the dissapearing selection temporarily, could you try to make bookmark? That should help mitigate the issue.

@msamsel msamsel requested a review from Comandeer May 8, 2018 09:59
@mlewand mlewand added the review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer. label Jul 18, 2018
@f1ames f1ames added the pr:frozen ❄ The pull request on which work was suspended due to various reasons. label Jan 16, 2020
@f1ames f1ames closed this Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:frozen ❄ The pull request on which work was suspended due to various reasons. review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partial selection outside and inside the table cause cells to be deleted when pressing Del or Backspace
4 participants