Skip to content

Commit

Permalink
merged PR timdown/rangy#405
Browse files Browse the repository at this point in the history
  • Loading branch information
pburrows committed Jan 2, 2019
1 parent b15aa47 commit 854b8ad
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/rangy-classapplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* Copyright 2019, Tim Down
* Licensed under the MIT license.
* Version: 1.3.2
* Version: 1.3.3
* Build date: 2 January 2019
*/
(function(factory, root) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rangy-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Copyright 2019, Tim Down
* Licensed under the MIT license.
* Version: 1.3.2
* Version: 1.3.3
* Build date: 2 January 2019
*/

Expand Down Expand Up @@ -109,7 +109,7 @@
};

var api = {
version: "1.3.2",
version: "1.3.3",
initialized: false,
isBrowser: isBrowser,
supported: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/rangy-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Copyright 2019, Tim Down
* Licensed under the MIT license.
* Version: 1.3.2
* Version: 1.3.3
* Build date: 2 January 2019
*/
(function(factory, root) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rangy-selectionsaverestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* Copyright 2019, Tim Down
* Licensed under the MIT license.
* Version: 1.3.2
* Version: 1.3.3
* Build date: 2 January 2019
*/
(function(factory, root) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rangy-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* Copyright 2019, Tim Down
* Licensed under the MIT license.
* Version: 1.3.2
* Version: 1.3.3
* Build date: 2 January 2019
*/
(function(factory, root) {
Expand Down
9 changes: 8 additions & 1 deletion lib/rangy-textrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* Copyright 2019, Tim Down
* Licensed under the MIT license.
* Version: 1.3.2
* Version: 1.3.3
* Build date: 2 January 2019
*/

Expand Down Expand Up @@ -1468,6 +1468,13 @@
currentChar = currentChar.toLowerCase();
}

// If there is a non-breaking space in the innerText, then replace with empty space " " so that it
// matches with the searchTerm. Based on the documentation, search should be performed on
// the visible text of the document
if (currentChar == "\u00a0") {
currentChar = " ";
}

if (backward) {
chars.unshift(pos);
text = currentChar + text;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rangy-updated",
"description": "A cross-browser DOM range and selection library, cloned from the original rangy repository, updated, and accepting PRs",
"version": "1.3.2",
"version": "1.3.3",
"author": {
"name": "Patrick Burrows",
"email": "[email protected]",
Expand Down
7 changes: 7 additions & 0 deletions src/modules/rangy-textrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,13 @@ rangy.createModule("TextRange", ["WrappedSelection"], function(api, module) {
currentChar = currentChar.toLowerCase();
}

// If there is a non-breaking space in the innerText, then replace with empty space " " so that it
// matches with the searchTerm. Based on the documentation, search should be performed on
// the visible text of the document
if (currentChar == "\u00a0") {
currentChar = " ";
}

if (backward) {
chars.unshift(pos);
text = currentChar + text;
Expand Down
36 changes: 36 additions & 0 deletions test/textrangetests.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,42 @@ xn.test.suite("Text Range module tests", function(s) {
t.assertFalse(range.findText("Two", options));
});

s.test("findText text with non-breaking space", function(t) {
t.el.innerHTML = 'One Two three';
var textNode = t.el.firstChild;
var range = rangy.createRange();
range.collapseToPoint(textNode, 0);

var scopeRange = rangy.createRange();
scopeRange.selectNodeContents(t.el);
var options = {
withinRange: scopeRange
};

t.assert(range.findText("Two ", options));
testRangeBoundaries(t, range, textNode, 4, textNode, 8);
range.collapse(false);
t.assertFalse(range.findText("Two", options));
});

s.test("findText text with non-breaking space and normal space", function(t) {
t.el.innerHTML = 'One Two  three';
var textNode = t.el.firstChild;
var range = rangy.createRange();
range.collapseToPoint(textNode, 0);

var scopeRange = rangy.createRange();
scopeRange.selectNodeContents(t.el);
var options = {
withinRange: scopeRange
};

t.assert(range.findText("Two three", options));
testRangeBoundaries(t, range, textNode, 4, textNode, 14);
range.collapse(false);
t.assertFalse(range.findText("Two", options));
});

s.test("findText simple text no wrap", function(t) {
t.el.innerHTML = 'Two One Two three';
var textNode = t.el.firstChild;
Expand Down

0 comments on commit 854b8ad

Please sign in to comment.