Skip to content

Commit

Permalink
Simplify JS search function
Browse files Browse the repository at this point in the history
- Do not overwrite the passed term variable in search()
- Passed search parameter overwrites currentSearchTerm
  • Loading branch information
versable committed Mar 4, 2020
1 parent 6b77cef commit 2c1291e
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions flamegraph.pl
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,7 @@ sub flow {
var params = get_params();
if (params.x && params.y)
zoom(find_group(document.querySelector('[x="' + params.x + '"][y="' + params.y + '"]')));
if (params.s) {
currentSearchTerm = params.s;
search();
}
if (params.s) search(params.s);
}
// event listeners
Expand Down Expand Up @@ -1042,10 +1039,7 @@ sub flow {
"allowed, eg: ^ext4_)"
+ (ignorecase ? ", ignoring case" : "")
+ "\\nPress Ctrl-i to toggle case sensitivity", "");
if (term != null) {
currentSearchTerm = term;
search();
}
if (term != null) search(term);
} else {
reset_search();
searching = 0;
Expand All @@ -1057,10 +1051,9 @@ sub flow {
}
}
function search(term) {
if (currentSearchTerm === null) return;
var term = currentSearchTerm;
if (term) currentSearchTerm = term;
var re = new RegExp(term, ignorecase ? 'i' : '');
var re = new RegExp(currentSearchTerm, ignorecase ? 'i' : '');
var el = document.getElementById("frames").children;
var matches = new Object();
var maxwidth = 0;
Expand Down Expand Up @@ -1097,7 +1090,7 @@ sub flow {
if (!searching)
return;
var params = get_params();
params.s = term;
params.s = currentSearchTerm;
history.replaceState(null, null, parse_params(params));
searchbtn.classList.add("show");
Expand Down

0 comments on commit 2c1291e

Please sign in to comment.