I looked at the search plugin's code and fiddled a bit with it. I could not come up with a immediate, perfect solution, but I ended up with this change:
if(this.settings.search.show_only_matches) {
this.element
.on("search.jstree", function (e, data) {
if(data.nodes.length) {
var matchingNodes = data.nodes; // change
$(this).find(".jstree-node").hide().filter('.jstree-last').filter(function() { return this.nextSibling; }).removeClass('jstree-last');
data.nodes.parentsUntil(".jstree").addBack().show()
.filter(".jstree-children").each(function () { $(this).children(".jstree-node:visible").eq(-1).addClass("jstree-last"); });
// nodes need to be in an expanded state
matchingNodes.find(".jstree-node").show(); // change
}
})
.on("clear_search.jstree", function (e, data) {
if(data.nodes.length) {
$(this).find(".jstree-node").css("display","").filter('.jstree-last').filter(function() { return this.nextSibling; }).removeClass('jstree-last');
}
});
}
The idea is to do the node hiding as before. After that, starting from the found nodes again, find all jstree-node and show them as well.
The above small code change only works when all nodes are fully expanded in the tree. Multiple clicks on the expand/collapse button also undo the above change again. I still understand the code too little to make that work properly.
Anyway, doing it like this shows the "problem" with nested search result nodes (which I believe would not be such a big problem). The above code change would result as in the following example:
Whereas without the above code change it looks like this:
I think the above behaviour (my hack) would be already an acceptable result from my point of view.
Of course, optimally only jstree-node(s) would be un-hided that have no siblings which are already included in the search result. So we would not see the nodes "Yahoo", "Youtube", and "Orkut", but we would see "Facebook", "Twitter", "Node 11" through "Node 15".
Something like the above would be my approach.
Best,
Yves