mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-04 19:05:45 +01:00
Fix removing search highlights from textareas.
Although firefox is happy to insert <span>s inside the DOM under textareas and inserts it won't find them with xpath.
This commit is contained in:
@@ -137,6 +137,7 @@ function Search() //{{{
|
|||||||
* Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
|
* Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
|
||||||
*/
|
*/
|
||||||
var highlightObj = {
|
var highlightObj = {
|
||||||
|
spans: [],
|
||||||
search: function (aWord, matchCase)
|
search: function (aWord, matchCase)
|
||||||
{
|
{
|
||||||
var finder = services.create("find");
|
var finder = services.create("find");
|
||||||
@@ -224,10 +225,32 @@ function Search() //{{{
|
|||||||
var parent = before.parentNode;
|
var parent = before.parentNode;
|
||||||
aNode.appendChild(docfrag);
|
aNode.appendChild(docfrag);
|
||||||
parent.insertBefore(aNode, before);
|
parent.insertBefore(aNode, before);
|
||||||
|
this.spans.push(aNode)
|
||||||
return 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 ()
|
clear: function ()
|
||||||
{
|
{
|
||||||
// FIXME: moves the selection
|
highlightObj.clear()
|
||||||
highlightObj.highlightDoc(window.content);
|
|
||||||
// need to manually collapse the selection if the document is not
|
|
||||||
// highlighted
|
|
||||||
getBrowser().fastFind.collapseSelection();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//}}}
|
//}}}
|
||||||
|
|||||||
Reference in New Issue
Block a user