From: Vladimír Vondruš Date: Tue, 1 Jan 2019 21:15:48 +0000 (+0100) Subject: doxygen: prevent search result being selected before the mouse moves. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=10f49c62c9fcbe794dadcac9a68533a23508918b;p=blog.git doxygen: prevent search result being selected before the mouse moves. Without this, the search was quite unusable with just the keyboard. --- 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 */