From 8659cf03da962f836227b569b790051eeb6170b0 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 9 Nov 2014 22:04:27 +0000 Subject: [PATCH] Attempted to improve search behaviour. Paper inputs don't fire `search` events, so listen for enter keyup instead. However, there's something wrong with search in that I can't get it to cycle through the matches any more. I tried to add the findNext variable usage, but it doesn't seem to have had any effect. --- resources/report/js/script.js | 16 +++++++++++++--- src/gui/handler.cpp | 9 +++------ src/gui/handler.h | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/resources/report/js/script.js b/resources/report/js/script.js index 87734eed..24ff3fdd 100644 --- a/resources/report/js/script.js +++ b/resources/report/js/script.js @@ -1069,7 +1069,16 @@ function hideHoverText(evt) { } } function startSearch(evt) { - if (evt.target.value == '') { + var findNext = false; + if (evt.type == 'keyup') { + if (evt.keyCode != 13) { + // Don't do anything for keyboard events that aren't enter - if valid, the input event will handle them. + return; + } else { + findNext = true; + } + } + if (evt.target.inputValue == '') { loot.query('cancelFind').then(function(result){ evt.target.focus(); }).catch(processCefError); @@ -1077,7 +1086,8 @@ function startSearch(evt) { var request = JSON.stringify({ name: 'find', args: [ - evt.target.value + evt.target.inputValue, + findNext ] }); @@ -1153,7 +1163,7 @@ function setupEventHandlers() { /* Set up event handlers for content search. */ var searchBox = document.getElementById('searchBox'); searchBox.addEventListener('input', startSearch, false); - searchBox.addEventListener('search', startSearch, false); + searchBox.addEventListener('keyup', startSearch, false); window.addEventListener('keyup', focusSearch, false); /* Set up handler for closing menus. */ diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index 94a36026..227c7a70 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -198,7 +198,7 @@ namespace loot { if (requestName == "find") { // Has one arg, which is the search string. - Find(browser, request["args"][0].as()); + Find(browser, request["args"][0].as(), request["args"][1].as()); callback->Success(""); return true; } @@ -334,14 +334,11 @@ namespace loot { return false; } - void Handler::Find(CefRefPtr browser, const std::string& search) { - // In case there is a search already running, cancel it. - browser->GetHost()->StopFinding(true); - + void Handler::Find(CefRefPtr browser, const std::string& search, bool findNext) { // Only one search at a time is allowed, so give a constant identifier, // and we want case-insensitive forward searching, with no repeated // searches. - browser->GetHost()->Find(0, search, true, false, false); + browser->GetHost()->Find(0, search, true, false, findNext); } void Handler::GetConflictingPlugins(const std::string& pluginName, CefRefPtr frame, CefRefPtr callback) { diff --git a/src/gui/handler.h b/src/gui/handler.h index 29cce50c..60a3cccf 100644 --- a/src/gui/handler.h +++ b/src/gui/handler.h @@ -66,7 +66,7 @@ namespace loot { YAML::Node& request, CefRefPtr callback); - void Find(CefRefPtr browser, const std::string& search); + void Find(CefRefPtr browser, const std::string& search, bool findNext); void GetConflictingPlugins(const std::string& pluginName, CefRefPtr frame, CefRefPtr callback); void CopyMetadata(const std::string& pluginName); std::string ClearPluginMetadata(const std::string& pluginName);