diff --git a/toolkit/components/satchel/nsFormAutoComplete.js b/toolkit/components/satchel/nsFormAutoComplete.js index d67806d6d52..b858bff296b 100644 --- a/toolkit/components/satchel/nsFormAutoComplete.js +++ b/toolkit/components/satchel/nsFormAutoComplete.js @@ -216,21 +216,21 @@ FormAutoComplete.prototype = { // of results in wrappedResult._values and only the results from // form history in wrappedResults.entries. // First, grab the entire list of old results. - let allResults = wrappedResult._values; + let allResults = wrappedResult._labels; let datalistResults, datalistLabels; if (allResults) { // We have datalist results, extract them from the values array. - datalistResults = allResults.slice(wrappedResult.entries.length); + datalistLabels = allResults.slice(wrappedResult.entries.length); let filtered = []; - datalistLabels = []; - for (let i = datalistResults.length; i > 0; --i) { - if (datalistResults[i - 1].contains(searchString)) { - filtered.push(datalistResults[i - 1]); - datalistLabels.push(wrappedResult._labels[i - 1]); + datalistResults = []; + for (let i = 0; i < datalistLabels.length; ++i) { + if (datalistLabels[i].toLowerCase().includes(searchString)) { + filtered.push(datalistLabels[i]); + datalistResults.push(wrappedResult._values[i]); } } - datalistResults = filtered; + datalistLabels = filtered; } let searchTokens = searchString.split(/\s+/); diff --git a/toolkit/components/satchel/test/test_form_autocomplete_with_list.html b/toolkit/components/satchel/test/test_form_autocomplete_with_list.html index 1cb35e04efa..e206c2135f4 100644 --- a/toolkit/components/satchel/test/test_form_autocomplete_with_list.html +++ b/toolkit/components/satchel/test/test_form_autocomplete_with_list.html @@ -203,6 +203,28 @@ function runTest() { doKey("return"); checkForm("Google"); + expectPopup(); + restoreForm(); + doKey("down"); + break; + + case 10: + // Test autocompletion of datalists with cached results. + sendString("PAS"); + waitForMenuChange(2); + break; + + case 11: + // Continuation of test 10 + sendString("S1"); + waitForMenuChange(1); + break; + + case 12: + doKey("down"); + doKey("return"); + checkForm("Google"); + // Trigger autocomplete popup // Look at form 3, try to trigger autocomplete popup input.value = "";