diff --git a/src/commands/insertList.js b/src/commands/insertList.js index 68711f8..6f06871 100644 --- a/src/commands/insertList.js +++ b/src/commands/insertList.js @@ -58,8 +58,9 @@ wysihtml5.commands.insertList = (function(wysihtml5) { // // becomes: // foo
bar
- composer.selection.executeAndRestore(function() { - var otherLists = getListsInSelection(otherNodeName, composer); + + composer.selection.executeAndRestoreRangy(function() { + otherLists = getListsInSelection(otherNodeName, composer); if (otherLists.length) { for (var l = otherLists.length; l--;) { wysihtml5.dom.renameElement(otherLists[l], nodeName.toLowerCase()); @@ -81,7 +82,7 @@ wysihtml5.commands.insertList = (function(wysihtml5) { // becomes: // // Also rename other lists in selection - composer.selection.executeAndRestore(function() { + composer.selection.executeAndRestoreRangy(function() { var renameLists = [el].concat(getListsInSelection(otherNodeName, composer)); // All selection inner lists get renamed too diff --git a/src/dom/resolve_list.js b/src/dom/resolve_list.js index d265bb7..a91b7d6 100644 --- a/src/dom/resolve_list.js +++ b/src/dom/resolve_list.js @@ -42,12 +42,15 @@ var doc = list.ownerDocument, fragment = doc.createDocumentFragment(), previousSibling = wysihtml5.dom.domNode(list).prev({ignoreBlankTexts: true}), + nextSibling = wysihtml5.dom.domNode(list).next({ignoreBlankTexts: true}), firstChild, lastChild, isLastChild, shouldAppendLineBreak, paragraph, - listItem; + listItem, + lastListItem = list.lastElementChild || list.lastChild, + isLastItem; if (useLineBreaks) { // Insert line break if list is after a non-block element @@ -57,10 +60,11 @@ while (listItem = (list.firstElementChild || list.firstChild)) { lastChild = listItem.lastChild; + isLastItem = listItem === lastListItem; while (firstChild = listItem.firstChild) { isLastChild = firstChild === lastChild; // This needs to be done before appending it to the fragment, as it otherwise will lose style information - shouldAppendLineBreak = isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild); + shouldAppendLineBreak = (!isLastItem || (nextSibling && !_isBlockElement(nextSibling))) && isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild); fragment.appendChild(firstChild); if (shouldAppendLineBreak) { _appendLineBreak(fragment); diff --git a/test/dom/resolve_list_test.js b/test/dom/resolve_list_test.js index 535ef6c..3f76aad 100644 --- a/test/dom/resolve_list_test.js +++ b/test/dom/resolve_list_test.js @@ -16,32 +16,41 @@ module("wysihtml5.dom.resolveList", { test("Basic tests (useLineBreaks = true)", function() { this.equal( this.resolveList("", true), - "foo
" + "foo", + "List with one li element resolved" + ); + + this.equal( + this.resolveList("Test", true), + "foo
Test", + "List with test after adds line break" ); this.equal( this.resolveList("", true), - "foo
bar
" + "foo
bar", + "List with two li elements resolved" ); this.equal( this.resolveList("
  1. foo
  2. bar
", true), - "foo
bar
" + "foo
bar", + "Numbered list with two li elements resolved" ); this.equal( this.resolveList("
  1. bar
", true), - "bar
" + "bar" ); this.equal( this.resolveList("
  1. foo
  2. bar
", true), - "foo
bar
" + "foo
bar" ); this.equal( this.resolveList("", true), - "

foo

bar
baz
" + "

foo

bar
baz" ); });