Skip to content

Commit

Permalink
Prevent insertion of <DIV> or <P> after leaving a list (still needs t…
Browse files Browse the repository at this point in the history
…o be tested in IE)
  • Loading branch information
Christopher Blum committed Dec 18, 2011
1 parent 215de8f commit b44f7bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/quirks/insert_line_break_on_return.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*/
(function(wysihtml5) {
var dom = wysihtml5.dom,
USE_NATIVE_LINE_BREAK_WHEN_CARET_INSIDE_TAGS = ["LI", "DIV", "P", "H1", "H2", "H3", "H4", "H5", "H6"],
USE_NATIVE_LINE_BREAK_WHEN_CARET_INSIDE_TAGS = ["LI", "P", "H1", "H2", "H3", "H4", "H5", "H6"],
LIST_TAGS = ["UL", "OL", "MENU"];

function keyPress(event) {
function keyDown(event) {
var keyCode = event.keyCode;

if (event.shiftKey || (keyCode !== wysihtml5.ENTER_KEY && keyCode !== wysihtml5.BACKSPACE_KEY)) {
Expand All @@ -34,6 +34,7 @@
setTimeout(function() {
var selectedNode = wysihtml5.selection.getSelectedNode(element.ownerDocument),
list,
invisibleSpace,
div;
if (!selectedNode) {
return;
Expand All @@ -46,10 +47,16 @@
if (list) {
return;
}
if (selectedNode.parentNode.nodeName === "P") {
div = dom.renameElement(selectedNode.parentNode, "div");
wysihtml5.selection.selectNode(div);

var parentElement = dom.getParentElement(selectedNode, { nodeName: ["P", "DIV"] }, 2);
if (!parentElement) {
return;
}

invisibleSpace = document.createTextNode(wysihtml5.INVISIBLE_SPACE);
dom.insert(invisibleSpace).before(parentElement);
dom.replaceWithChildNodes(parentElement);
wysihtml5.selection.selectNode(invisibleSpace);
}, 0);
}
return;
Expand All @@ -63,6 +70,6 @@

wysihtml5.quirks.insertLineBreakOnReturn = function(element) {
// keypress doesn't fire when you hit backspace
dom.observe(element.ownerDocument, "keydown", keyPress);
dom.observe(element.ownerDocument, "keydown", keyDown);
};
})(wysihtml5);
2 changes: 1 addition & 1 deletion src/views/composer.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
*/
var focusWithoutScrolling = function(element) {
if (element.setActive) {
// Following line could cause a js error when the editor is invisible
// Following line could cause a js error when the textarea is invisible
// See https://github.com/xing/wysihtml5/issues/9
try { element.setActive(); } catch(e) {}
} else {
Expand Down

0 comments on commit b44f7bd

Please sign in to comment.