Fix search behavior

Before, it was always searching for the current term without
the last entered (or with the last deleted) character. This
behavior is fixed now. Also, an empty query will now match
(hopefully) nothing instead of everything.
This commit is contained in:
Markus Koch 2020-04-25 17:34:33 +02:00
parent d229044ebf
commit 5b5ce97a1a

View File

@ -292,7 +292,7 @@ function toggle_search() {
search_element.style.overflow = "scroll"; search_element.style.overflow = "scroll";
search_element.style.padding = "6px"; search_element.style.padding = "6px";
search_element.style.height = "100%"; search_element.style.height = "100%";
search_element.innerHTML = '<input style="width:100%;" id="search_query" name="lifo_map_search" type="search" placeholder="Start typing to search..." onkeypress="search(event)"><div id="search_results"></div>' ; search_element.innerHTML = '<input style="width:100%;" id="search_query" name="lifo_map_search" type="search" placeholder="Start typing to search..." oninput="search(event)"><div id="search_results"></div>' ;
} }
td = document.getElementById('windowtr').insertCell(0); td = document.getElementById('windowtr').insertCell(0);
@ -302,7 +302,7 @@ function toggle_search() {
td.id = "searchbar"; td.id = "searchbar";
td.appendChild(search_element); td.appendChild(search_element);
document.getElementById('search_query').focus(); document.getElementById('search_query').select();
} }
function htmlEntities(str) { function htmlEntities(str) {
@ -321,7 +321,9 @@ var default_street_color = "#3388ff";
function search(e) { function search(e) {
var query = document.getElementById("search_query").value; var query = document.getElementById("search_query").value;
document.getElementById('search_results').innerHTML = ""; document.getElementById('search_results').innerHTML = "";
if (query.length > 0 || e.key == "Enter") { if (true) {
if (query.length == 0)
query = "!@#$%^&"; // Cheap workaround to (hopefully) match nothing
results = document.createElement("ul"); results = document.createElement("ul");
for (var i = 0; i < layers._layers.length; i++) { for (var i = 0; i < layers._layers.length; i++) {
if (!layers._layers[i].layer._layers) if (!layers._layers[i].layer._layers)