Skip to content

Commit

Permalink
Merge pull request #523 from wjt/faster-highlight-creation
Browse files Browse the repository at this point in the history
Faster highlight creation
  • Loading branch information
tilgovi committed May 3, 2015
2 parents cb8d6c4 + 2b2700e commit e355de6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ui/highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ function highlightRange(normedRange, cssClass) {
}
var white = /^\s*$/;

var hl = $("<span class='" + cssClass + "'></span>");

// Ignore text nodes that contain only whitespace characters. This prevents
// spans being injected between elements that can only contain a restricted
// subset of nodes such as table rows and lists. This does mean that there
Expand All @@ -33,9 +31,11 @@ function highlightRange(normedRange, cssClass) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (!white.test(node.nodeValue)) {
results.push(
$(node).wrapAll(hl).parent().show()[0]
);
var hl = document.createElement('span');
hl.className = cssClass;
node.parentNode.replaceChild(hl, node);
hl.appendChild(node);
results.push(hl);
}
}
return results;
Expand Down

0 comments on commit e355de6

Please sign in to comment.