From bde1a4432fef4cb2f5fe8ab600e72ab5b8b4830d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= <ged@odoo.com>
Date: Thu, 20 Nov 2014 10:26:13 +0100
Subject: [PATCH] [FIX] fix autocompletion problems with quick presses

Problem was that when the user types quickly in the search bar and press
enter, the keydown event of the enter key happens before the keypress
event of the last key entered.  This means that the autocompletion has
a wrong string.  The fix is to move the enter selection detection from
keydown to keyup.
---
 addons/web/static/src/js/search.js | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index 9b155054774f..e1b96d5d7fc6 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -2362,6 +2362,12 @@ instance.web.search.AutoComplete = instance.web.Widget.extend({
                 ev.preventDefault();
                 return;
             }
+            if (ev.which === $.ui.keyCode.ENTER) {
+                if (self.current_result && self.get_search_string().length) {
+                    self.select_item(ev);
+                }
+                return;
+            }
             if (!self.searching) {
                 self.searching = true;
                 return;
@@ -2377,7 +2383,6 @@ instance.web.search.AutoComplete = instance.web.Widget.extend({
         this.$input.on('keydown', function (ev) {
             switch (ev.which) {
                 case $.ui.keyCode.TAB:
-                case $.ui.keyCode.ENTER:
                     if (self.current_result && self.get_search_string().length) {
                         self.select_item(ev);
                     }
-- 
GitLab