From 10f49c62c9fcbe794dadcac9a68533a23508918b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 1 Jan 2019 22:15:48 +0100 Subject: [PATCH] doxygen: prevent search result being selected before the mouse moves. Without this, the search was quite unusable with just the keyboard. --- doxygen/search.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doxygen/search.js b/doxygen/search.js index c95260af..3108a1a4 100644 --- a/doxygen/search.js +++ b/doxygen/search.js @@ -36,6 +36,10 @@ var Search = { searchString: '', searchStack: [], + /* So items don't get selected right away when a cursor is over results but + only after mouse moves */ + mouseMovedSinceLastRender: false, + init: function(buffer, maxResults) { let view = new DataView(buffer); @@ -459,11 +463,17 @@ var Search = { document.getElementById('search-results').style.display = 'none'; document.getElementById('search-notfound').style.display = 'block'; } + + /* Don't allow things to be selected just by motionless mouse cursor + suddenly appearing over a search result */ + this.mouseMovedSinceLastRender = false; }, }; /* istanbul ignore next */ function selectResult(event) { + if(!Search.mouseMovedSinceLastRender) return; + if(event.currentTarget.parentNode.id == 'search-current') return; let current = document.getElementById('search-current'); @@ -569,6 +579,13 @@ if(typeof document !== 'undefined') { } } }; + + /* Allow selecting items by mouse hover only after it moves once the + results are populated. This prevents a random item getting selected if + the cursor is left motionless over the result area. */ + document.getElementById('search-results').onmousemove = function() { + Search.mouseMovedSinceLastRender = true; + }; } /* For Node.js testing */ /* istanbul ignore else */ -- 2.30.2