diff --git a/src/gui/html/js/events.js b/src/gui/html/js/events.js index d35cd6f8..37583f1d 100644 --- a/src/gui/html/js/events.js +++ b/src/gui/html/js/events.js @@ -576,6 +576,34 @@ function onSearchOpen() { document.getElementById('mainToolbar').classList.add('search'); document.getElementById('searchBar').focusInput(); } -function onSearchClose() { +function onSearchBegin(evt) { + loot.game.plugins.forEach((plugin) => { + plugin.isSearchResult = false; + }); + + if (!evt.detail.needle) { + return; + } + + // Don't push to the target's results property directly, as the + // change observer doesn't work correctly unless special Polymer APIs + // are used, which I don't want to get into. + const results = []; + loot.game.plugins.forEach((plugin, index) => { + if (plugin.getCardContent(loot.filters).containsText(evt.detail.needle)) { + results.push(index); + plugin.isSearchResult = true; + } + }); + + evt.target.results = results; +} +function onSearchChangeSelection(evt) { + document.getElementById('pluginCardList').scrollToIndex(evt.detail.selection); +} +function onSearchEnd(evt) { + loot.game.plugins.forEach((plugin) => { + plugin.isSearchResult = false; + }); document.getElementById('mainToolbar').classList.remove('search'); } diff --git a/src/gui/html/js/init.js b/src/gui/html/js/init.js index 89bb1d13..32487221 100644 --- a/src/gui/html/js/init.js +++ b/src/gui/html/js/init.js @@ -75,7 +75,9 @@ /* Set up search event handlers. */ document.getElementById('showSearch').addEventListener('click', onSearchOpen); - document.getElementById('searchBar').addEventListener('loot-search-close', onSearchClose); + document.getElementById('searchBar').addEventListener('loot-search-begin', onSearchBegin); + document.getElementById('searchBar').addEventListener('loot-search-change-selection', onSearchChangeSelection, false); + document.getElementById('searchBar').addEventListener('loot-search-end', onSearchEnd); window.addEventListener('keyup', onFocusSearch); /* Set up event handlers for settings dialog. */