Skip to content

Commit

Permalink
Reimplemented end_container_on_empty_block option and added unit test…
Browse files Browse the repository at this point in the history
…s for it.
  • Loading branch information
spocke committed Mar 12, 2012
1 parent f2baca5 commit a81389e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion jscripts/tiny_mce/classes/EnterKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions tests/tinymce.EnterKey.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
autostart: false,
setup: function() {
editor.settings.forced_root_block = 'p';
editor.settings.end_container_on_empty_block = false;
}
});

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a81389e

Please sign in to comment.