From ec2531065476332647ccad8fe4d82691799f64c7 Mon Sep 17 00:00:00 2001 From: N-Shar-ma Date: Wed, 2 Feb 2022 13:07:15 +0530 Subject: [PATCH] typeahead: Fix typeahead for custom selection triggers. Now checking for custom trigger keys will happen during `keydown` instead of `keyup` so that if the key is printable, `preventDefault` can prevent it from appearing in the compose box. This fixes the case when jumping to topic, would eat up any space or new line after the cursor, due to wrong splitting around the cursor, which was a result of using the printable custom trigger key, the ">", in contrast to a non printable one like Enter. The problem was that custom trigger keys like `>` that the browser's default behavior is to type (vs. others like RightArrow where that isn't the case) can result in extra characters being emitted, which is not wanted. --- static/third/bootstrap-typeahead/typeahead.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/static/third/bootstrap-typeahead/typeahead.js b/static/third/bootstrap-typeahead/typeahead.js index 285430ba3b..dbb3a15a1f 100644 --- a/static/third/bootstrap-typeahead/typeahead.js +++ b/static/third/bootstrap-typeahead/typeahead.js @@ -376,6 +376,11 @@ } , keydown: function (e) { + if (this.trigger_selection(e)) { + if (!this.shown) return; + e.preventDefault(); + this.select(e); + } this.suppressKeyPressRepeat = !~$.inArray(e.keyCode, [40,38,9,13,27]) this.move(e) } @@ -406,10 +411,6 @@ break default: - if (this.trigger_selection(e)) { - if (!this.shown) return; - this.select(e); - } var hideOnEmpty = false if (e.keyCode === 8 && this.options.helpOnEmptyStrings) { // backspace hideOnEmpty = true