chiark / gitweb /
doxygen: prevent search result being selected before the mouse moves.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 1 Jan 2019 21:15:48 +0000 (22:15 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 2 Jan 2019 21:07:11 +0000 (22:07 +0100)
Without this, the search was quite unusable with just the keyboard.

doxygen/search.js

index c95260af2d32750a319d257976d9851cec9f8f52..3108a1a4bdca075ce0d73b766cd2e5b32ca41fd2 100644 (file)
@@ -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 */