diff --git a/build/squire-raw.js b/build/squire-raw.js
index 346badc..47446be 100644
--- a/build/squire-raw.js
+++ b/build/squire-raw.js
@@ -3637,7 +3637,7 @@ proto.setTextDirection = function ( direction ) {
function forEachChildInRange( rootNode, range, iterator ) {
- var walker = new TreeWalker( rootNode, SHOW_ELEMENT,
+ var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT,
function ( node ) {
return node.parentNode === rootNode &&
isNodeContainedInRange( range, node, false /* include partials */ );
diff --git a/source/Editor.js b/source/Editor.js
index a31af13..b66cdb1 100644
--- a/source/Editor.js
+++ b/source/Editor.js
@@ -2179,7 +2179,7 @@ proto.setTextDirection = function ( direction ) {
function forEachChildInRange( rootNode, range, iterator ) {
- var walker = new TreeWalker( rootNode, SHOW_ELEMENT,
+ var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT,
function ( node ) {
return node.parentNode === rootNode &&
isNodeContainedInRange( range, node, false /* include partials */ );
diff --git a/test/blank.html b/test/blank.html
new file mode 100644
index 0000000..e69de29
diff --git a/test/squire.spec.js b/test/squire.spec.js
index d495672..363b53a 100644
--- a/test/squire.spec.js
+++ b/test/squire.spec.js
@@ -12,7 +12,9 @@ expect = expect.clone()
})
.addAssertion('[not] to contain HTML', function (expect, editor, expectedValue) {
this.errorMode = 'bubble';
- expect(editor.getHTML(), '[not] to be', expectedValue);
+ var actualHTML = editor.getHTML().replace(/
/g, '');
+ // BR tags are inconsistent across browsers. Removing them allows cross-browser testing.
+ expect(actualHTML, '[not] to be', expectedValue);
});
describe('Squire RTE', function () {
@@ -25,45 +27,46 @@ describe('Squire RTE', function () {
function selectAll(editor) {
var range = doc.createRange();
- range.setStartBefore(doc.body.childNodes.item(0));
- range.setEndAfter(doc.body.childNodes.item(0));
+ range.setStart(doc.body.childNodes.item(0), 0);
+ range.setEnd(doc.body.childNodes.item(0), doc.body.childNodes.item(0).childNodes.length);
editor.setSelection(range);
}
- describe('removeAllFormatting()', function () {
+ describe('removeAllFormatting', function () {
// Trivial cases
it('removes inline styles', function () {
- var startHTML = '
one two three four five
';
+ var startHTML = 'one two three four five
';
editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML);
selectAll(editor);
editor.removeAllFormatting();
- expect(editor, 'to contain HTML', '
one two three four five
');
+ expect(editor, 'to contain HTML', 'one two three four five
');
});
it('removes block styles', function () {
- var startHTML = '';
+ var startHTML = '';
editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML);
selectAll(editor);
editor.removeAllFormatting();
- expect(editor, 'to contain HTML', '
one
two
three
four
five
');
+ var expectedHTML = '';
+ expect(editor, 'to contain HTML', expectedHTML);
});
// Potential bugs
it('removes styles that begin inside the range', function () {
- var startHTML = 'one two three four five
';
+ var startHTML = 'one two three four five
';
editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange();
range.setStart(doc.body.childNodes.item(0), 0);
range.setEnd(doc.getElementsByTagName('i').item(0).childNodes.item(0), 4);
editor.removeAllFormatting(range);
- expect(editor, 'to contain HTML', 'one two three four five
');
+ expect(editor, 'to contain HTML', 'one two three four five
');
});
it('removes styles that end inside the range', function () {
- var startHTML = 'one two three four five
';
+ var startHTML = 'one two three four five
';
editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange();
@@ -74,7 +77,7 @@ describe('Squire RTE', function () {
});
it('removes styles enclosed by the range', function () {
- var startHTML = 'one two three four five
';
+ var startHTML = 'one two three four five
';
editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange();
@@ -85,34 +88,34 @@ describe('Squire RTE', function () {
});
it('removes styles enclosing the range', function () {
- var startHTML = 'one two three four five
';
+ var startHTML = 'one two three four five
';
editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange();
range.setStart(doc.getElementsByTagName('i').item(0).childNodes.item(0), 4);
range.setEnd(doc.getElementsByTagName('i').item(0).childNodes.item(0), 18);
editor.removeAllFormatting(range);
- expect(editor, 'to contain HTML', 'one two three four five
');
+ expect(editor, 'to contain HTML', 'one two three four five
');
});
it('removes nested styles and closes tags correctly', function () {
- var startHTML = '';
+ var startHTML = '';
editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange();
range.setStart(doc.getElementsByTagName('td').item(1), 0);
range.setEnd(doc.getElementsByTagName('td').item(2), doc.getElementsByTagName('td').item(2).childNodes.length);
editor.removeAllFormatting(range);
- expect(editor, 'to contain HTML', '' +
- '
two
' +
- '
three
' +
- '');
+ expect(editor, 'to contain HTML', '' +
+ 'two
' +
+ 'three
' +
+ '');
});
});
afterEach(function () {
editor = null;
var iframe = document.getElementById('testFrame');
- iframe.src = 'about:blank';
+ iframe.src = 'blank.html';
});
});