Skip to content

Commit

Permalink
Fix IE list creation toggle problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Pulges committed Dec 16, 2015
1 parent 193e611 commit b6b95e1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions src/commands/insertList.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ wysihtml5.commands.insertList = (function(wysihtml5) {
for (var i = innerLists.length; i--;) {
wysihtml5.dom.resolveList(innerLists[i], composer.config.useLineBreaks);
}
wysihtml5.dom.resolveList(el, composer.config.useLineBreaks);
if (innerLists.length === 0) {
wysihtml5.dom.resolveList(el, composer.config.useLineBreaks);
}
}
});
};
Expand Down Expand Up @@ -138,8 +140,34 @@ wysihtml5.commands.insertList = (function(wysihtml5) {
exec: function(composer, command, nodeName) {
var doc = composer.doc,
cmd = (nodeName === "OL") ? "insertOrderedList" : "insertUnorderedList",
selectedNode = composer.selection.getSelectedNode(),
list = findListEl(selectedNode, nodeName, composer);
s = composer.selection.getSelection(),
anode = s.anchorNode.nodeType === 1 && s.anchorNode.firstChild ? s.anchorNode.childNodes[s.anchorOffset] : s.anchorNode,
fnode = s.focusNode.nodeType === 1 && s.focusNode.firstChild ? s.focusNode.childNodes[s.focusOffset] || s.focusNode.lastChild : s.focusNode,
selectedNode, list;

if (s.isBackwards()) {
// swap variables
anode = [fnode, fnode = anode][0];
}

if (wysihtml5.dom.domNode(fnode).is.emptyTextNode(true) && fnode) {
fnode = wysihtml5.dom.domNode(fnode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
}
if (wysihtml5.dom.domNode(anode).is.emptyTextNode(true) && anode) {
anode = wysihtml5.dom.domNode(anode).next({nodeTypes: [1,3], ignoreBlankTexts: true});
}

if (anode && fnode) {
if (anode === fnode) {
selectedNode = anode;
} else {
selectedNode = wysihtml5.dom.domNode(anode).commonAncestor(fnode, composer.element);
}
} else {
selectedNode = composer.selection.getSelectedNode();
}

list = findListEl(selectedNode, nodeName, composer);

if (!list.el) {
if (composer.commands.support(cmd)) {
Expand Down
2 changes: 1 addition & 1 deletion src/dom/dom_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
is: {
emptyTextNode: function(ignoreWhitespace) {
var regx = ignoreWhitespace ? (/^\s*$/g) : (/^[\r\n]*$/g);
return node.nodeType === wysihtml5.TEXT_NODE && (regx).test(node.data);
return node && node.nodeType === wysihtml5.TEXT_NODE && (regx).test(node.data);
},

visible: function() {
Expand Down

0 comments on commit b6b95e1

Please sign in to comment.