diff --git a/bower.json b/bower.json index 6e2c872b..9206c74b 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "scribe", "dependencies": { "lodash-amd": "2.4.1", - "scribe-common": "0.0.4" + "scribe-common": "0.0.11" }, "devDependencies": { "requirejs": "~2.1.9", diff --git a/package.json b/package.json index 0754d620..3c037538 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "main": "src/scribe.js", "dependencies": { "lodash-amd": "~2.4.1", - "scribe-common": "~0.0.4" + "scribe-common": "~0.0.11" }, "devDependencies": { "chai": "~1.9.1", diff --git a/src/plugins/core/formatters/html/ensure-selectable-containers.js b/src/plugins/core/formatters/html/ensure-selectable-containers.js index aa5672fb..6a64cef2 100644 --- a/src/plugins/core/formatters/html/ensure-selectable-containers.js +++ b/src/plugins/core/formatters/html/ensure-selectable-containers.js @@ -17,6 +17,15 @@ define([ // http://www.w3.org/TR/html-markup/syntax.html#syntax-elements var html5VoidElements = ['AREA', 'BASE', 'BR', 'COL', 'COMMAND', 'EMBED', 'HR', 'IMG', 'INPUT', 'KEYGEN', 'LINK', 'META', 'PARAM', 'SOURCE', 'TRACK', 'WBR']; + function parentHasNoTextContent(node) { + if (element.isCaretPositionNode(node)) { + return true; + } else { + return node.parentNode.textContent.trim() === ''; + } + } + + function traverse(parentNode) { // Instead of TreeWalker, which gets confused when the BR is added to the dom, // we recursively traverse the tree to look for an empty node that can have childNodes @@ -24,9 +33,18 @@ define([ var node = parentNode.firstElementChild; function isEmpty(node) { - return node.children.length === 0 - || (node.children.length === 1 - && element.isSelectionMarkerNode(node.children[0])); + + if ((node.children.length === 0 && element.isBlockElement(node)) + || (node.children.length === 1 && element.isSelectionMarkerNode(node.children[0]))) { + return true; + } + + // Do not insert BR in empty non block elements with parent containing text + if (!element.isBlockElement(node) && node.children.length === 0) { + return parentHasNoTextContent(node); + } + + return false; } while (node) {