-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
plugins/wysiwygarea/plugin.js
Outdated
@@ -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) |
There was a problem hiding this comment.
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() ) ) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- Simulate
keydown
to register listeners ondiv
by superflous function. - Reload snapshot, to simulate Ctrl+Z, when previous snapshot is restored.
- 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). - 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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
.
plugins/wysiwygarea/plugin.js
Outdated
} 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 ) { |
There was a problem hiding this comment.
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' ) |
There was a problem hiding this comment.
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(); | ||
} ); | ||
}); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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 ofdiv
on the green background.
|
||
bender.test( { | ||
// #704 | ||
'test keeping widget wrapper in editor when superflous elemnts are checked': function() { |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. ;)
…4.xxx Edge version.
- ignore manual tests on non-edge browser and omit usage of addEventListener - typo fixes - syntax fixes
I've made fixes and rebase branch to major. Also switch target branch on github to major. |
Ctrl+Z
in EdgeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
What is the purpose of this pull request?
Bug fix
Does your PR contain necessary tests?
yes
This PR contains
What changes did you make?
div
in Edge.div
).Close #704