From 6e1c9999345892bd7070f22e1023b9faa0b6d232 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 2 Apr 2009 00:09:33 +0100 Subject: [PATCH] Fix removing search highlights from textareas. Although firefox is happy to insert s inside the DOM under textareas and inserts it won't find them with xpath. --- common/content/find.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/common/content/find.js b/common/content/find.js index 1599bc00..b6e9afe7 100644 --- a/common/content/find.js +++ b/common/content/find.js @@ -137,6 +137,7 @@ function Search() //{{{ * Graeme McCutcheon */ var highlightObj = { + spans: [], search: function (aWord, matchCase) { var finder = services.create("find"); @@ -224,10 +225,32 @@ function Search() //{{{ var parent = before.parentNode; aNode.appendChild(docfrag); parent.insertBefore(aNode, before); + this.spans.push(aNode) return aNode; }, - getSpans: function (doc) buffer.evaluateXPath("//*[@liberator:highlight='Search']", doc) + /** + * Clears all search highlighting. + */ + clear: function () + { + this.spans.forEach(function (span) + { + if (span.parentNode) + { + let el = span.firstChild + while (el) + { + span.removeChild(el) + span.parentNode.insertBefore(el, span) + el = span.firstChild; + } + span.parentNode.removeChild(span); + } + }) + this.spans = [] + }, + getSpans: function (doc) this.spans }; /////////////////////////////////////////////////////////////////////////////}}} @@ -499,11 +522,7 @@ function Search() //{{{ */ clear: function () { - // FIXME: moves the selection - highlightObj.highlightDoc(window.content); - // need to manually collapse the selection if the document is not - // highlighted - getBrowser().fastFind.collapseSelection(); + highlightObj.clear() } }; //}}}