Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reimplemented end_container_on_empty_block option and added unit test…

…s for it.
  • Loading branch information...
commit a81389e7cc189cdc20226233a481de468464e51f 1 parent f2baca5
@spocke spocke authored
View
8 jscripts/tiny_mce/classes/EnterKey.js
@@ -321,7 +321,13 @@
newBlock = createNewBlock();
}
- dom.insertAfter(newBlock, parentBlock);
+ // Split the current container block element if enter is pressed inside an empty inner block element
+ if (settings.end_container_on_empty_block && /^(HGROUP|BLOCKQUOTE|SECTION|ARTICLE)$/.test(containerBlockName) && dom.isEmpty(parentBlock)) {
+ // Split container block for example a BLOCKQUOTE at the current blockParent location for example a P
+ newBlock = dom.split(containerBlock, parentBlock);
+ } else {
+ dom.insertAfter(newBlock, parentBlock);
+ }
} else if (isCaretAtStartOrEndOfBlock(true)) {
// Insert new block before
newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
View
25 tests/tinymce.EnterKey.html
@@ -19,6 +19,7 @@
autostart: false,
setup: function() {
editor.settings.forced_root_block = 'p';
+ editor.settings.end_container_on_empty_block = false;
}
});
@@ -216,6 +217,30 @@
equal(cleanHtml(editor.getBody().innerHTML), tinymce.isIE ? '<p>abc<br></p>' : '<p>abc<br><br></p>');
});
+test('Enter in empty P at the end of a blockquote and end_container_on_empty_block: true', function() {
+ editor.settings.end_container_on_empty_block = true;
+ editor.getBody().innerHTML = tinymce.isIE ? '<blockquote><p>abc</p><p></p></blockquote>' : '<blockquote><p>abc</p><p><br></p></blockquote>';
+ setSelection('p:last', 0);
+ pressEnter();
+ equal(editor.getContent(), '<blockquote><p>abc</p></blockquote><p>\u00a0</p>');
+});
+
+test('Enter in empty P at the beginning of a blockquote and end_container_on_empty_block: true', function() {
+ editor.settings.end_container_on_empty_block = true;
+ editor.getBody().innerHTML = tinymce.isIE ? '<blockquote><p></p><p>abc</p></blockquote>' : '<blockquote><p><br></p><p>abc</p></blockquote>';
+ setSelection('p', 0);
+ pressEnter();
+ equal(editor.getContent(), '<p>\u00a0</p><blockquote><p>abc</p></blockquote>');
+});
+
+test('Enter in empty P at in the middle of a blockquote and end_container_on_empty_block: true', function() {
+ editor.settings.end_container_on_empty_block = true;
+ editor.getBody().innerHTML = tinymce.isIE ? '<blockquote><p>abc</p><p></p><p>123</p></blockquote>' : '<blockquote><p>abc</p><p><br></p><p>123</p></blockquote>';
+ setSelection('p:nth-child(2)', 0);
+ pressEnter();
+ equal(editor.getContent(), '<blockquote><p>abc</p></blockquote><p>\u00a0</p><blockquote><p>123</p></blockquote>');
+});
+
if (tinymce.isIE) {
test('Enter inside empty P with empty P siblings', function() {
// Tests that a workaround for an IE bug is working correctly
Please sign in to comment.
Something went wrong with that request. Please try again.