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

[#704] Fix broken widget after using Ctrl+Z in Edge #734

Merged
merged 9 commits into from
Sep 13, 2017
Merged

[#704] Fix broken widget after using Ctrl+Z in Edge #734

merged 9 commits into from
Sep 13, 2017

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Aug 7, 2017

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

yes

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • Modify condition which remove unnecessary div in Edge.
  • Modify condition to work only in Edge up to 14.xxx. (Edge 15 doesn't add div).
  • Modify tests to respect new condition related to Edge version.

Close #704

@@ -164,7 +164,7 @@
// Prevent IE/Edge from leaving a new paragraph/div after deleting all contents in body. (http://dev.ckeditor.com/ticket/6966, http://dev.ckeditor.com/ticket/13142)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you adjust the description to make it clear that this case does not happen in Edge > 15?
You could also reformat the comment so tickets reference is consistent with our convention (ticket reference before . not after .).

@@ -297,7 +297,7 @@
var elements = doc.getElementsByTag( tagName );
if ( lockRetain ) {
if ( elements.count() == 1 && !elements.getItem( 0 ).getCustomData( 'retain' ) &&
!elements.getItem( 0 ).hasAttribute( 'data-cke-temp' ) ) {
CKEDITOR.tools.isEmpty( elements.getItem( 0 ).getAttributes() ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason of this change? Previously elements without data-cke-temp attribute (so not temporary elements) were removed inside this if, now it removes only attributeless elements. Is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Entire function removeSuperfluousElement was design to remove additional div which appear in Edge, when all text is removed from editor. This div never had any attribute. Unfortunately author hadn't predict that not only those extra divs might appear, but also widgets might be construct based on div. And in case of undo command entire widget might be redraw so we lost retain customData attached to div.
This change detects more carefully only those extra divs from Edge, so it becomes more specific. Now divs connected to widgets won't be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense 👍

var editor = CKEDITOR.replace( 'editor1', {
height: '600px'
} );
setInterval( function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could listen to change event here instead of using timeout, so it should be more reliable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately change event is not working as it should. :( It's execute before keyup listener removes div from wysiwygarea. I've used keyup listener instead.

@bender-ckeditor-plugins: image2, wysiwygarea, undo, sourcearea

----
1. Put caret in the text on the right and type some character.
Copy link
Contributor

Choose a reason for hiding this comment

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

type some text.

sounds a little better IMHO.

} ) );

var snap = editor.getSnapshot();
editor.loadSnapshot( snap );
Copy link
Contributor

Choose a reason for hiding this comment

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

This two lines just reload the snapshot, it it needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.
keydown and keyup don't trigger undo command, which triggers re-creating widget (there even is no history to revert it).
So this simulation works as follows:

  1. Simulate keydown to register listeners on div by superflous function.
  2. Reload snapshot, to simulate Ctrl+Z, when previous snapshot is restored.
  3. Reloading snapshot automatically triggers re-creating widget. Here will be destroyed wrapping div for widget, and retain attribute will be lost (as it happens in Edge).
  4. Simulate keyup to execute proper listener from superflous function.

Re-loading snapshot might be replaced with some kind of triggering undo event, but it would require much more work. First to make some history, and then revert it. So I extract only important part from entire undo process, which is reloading snapshot, what cause the issue in case of using shortcut. This allows on proper simulation behaviour on Edge and proper fail of test in case of Edge environment without bug fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense 👍

@@ -44,8 +44,8 @@ bender.test( {
wait();
},

'Test removing superfluous <div> inserted by Edge': function() {
if ( !CKEDITOR.env.edge ) {
'Test removing superfluous <div> inserted by Edge < v15': function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it is not your code, but could you change Test removing... to test removing...? It should be lowercased. Please update all test names in this file if necessary.

Also inserted by Edge < v15, I think < 15 is not needed, as it is also in ignore condition right below test name.

@@ -227,5 +227,31 @@ bender.test( {
} );
} );
wait();
},

'Test not-removing <div> with any attributes in Edge < v15': function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be not removing instead of not-removing.

} else if ( CKEDITOR.env.edge && editor.enterMode != CKEDITOR.ENTER_DIV ) {
}
// From version Edge 15 additional `div` are not added to the editor.
else if ( CKEDITOR.env.edge && editor.enterMode != CKEDITOR.ENTER_DIV && CKEDITOR.env.version < 15 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rearranging this if as:

CKEDITOR.env.edge && CKEDITOR.env.version < 15 && editor.enterMode != CKEDITOR.ENTER_DIV

will make it more readable IMHO.

var editor = CKEDITOR.replace( 'editor1', {
height: '600px'
} );
var output = document.getElementById( 'output' )
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 end of this line.

editor.editable().$.addEventListener( 'keyup', function() {
output.innerText = editor.editable().getFirst().getName();
} );
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be } ); instead of });.

} ) );

var snap = editor.getSnapshot();
editor.loadSnapshot( snap );
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense 👍

1. Put caret in the text on the right and type some text.
1. Use `Ctrl + Z` or `Cmd + Z` shortcut to make undo few times.

**Expected:** Text returns to previous form. Below editor will be written `div` on green background.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe:

Text returns to previous form. Below the editor, you should see div on green background.


**Expected:** Text returns to previous form. Below editor will be written `div` on green background.

**Unexpected:** Text moves below the image. Below editor will be written `figure` instead of `div`.
Copy link
Contributor

Choose a reason for hiding this comment

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

And:

Text moves below the image. Below editor, it will be written figure instead of div on the green background.


bender.test( {
// #704
'test keeping widget wrapper in editor when superflous elemnts are checked': function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo:

test keeping widget wrapper in editor when superfluous elements are checked

@@ -0,0 +1,22 @@
<textarea id="editor1" name="editor1">
Copy link
Contributor

Choose a reason for hiding this comment

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

This test fails on IE8 due to addEventListener, if it should be run only for Edge add a proper bender.ignore or fix attaching listener if it should be run also for IE8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added both things. I know it wasn't necessary, but this not harm anything. ;)

@msamsel msamsel changed the base branch from master to major September 13, 2017 10:54
@msamsel
Copy link
Contributor Author

msamsel commented Sep 13, 2017

I've made fixes and rebase branch to major. Also switch target branch on github to major.

@msamsel msamsel changed the title Fix broken widget after using Ctrl+Z in Edge [#704] Fix broken widget after using Ctrl+Z in Edge Sep 13, 2017
@f1ames f1ames self-requested a review September 13, 2017 12: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.

LGTM 👍

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.

Broken content in article editor after using shortcut CTRL+Z
2 participants