From 36b0137968e59d8b026a229c7e9433a8a4943400 Mon Sep 17 00:00:00 2001 From: Romit Choudhary Date: Mon, 10 May 2021 14:34:14 +0000 Subject: [PATCH] Fixes #3495 - Selecting Textmodules, Knowledge Base Articles and the Mentions Feature are not working for mobile devices --- .../javascripts/app/lib/base/jquery.textmodule.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/lib/base/jquery.textmodule.js b/app/assets/javascripts/app/lib/base/jquery.textmodule.js index 68eda5f22..2da57c5de 100644 --- a/app/assets/javascripts/app/lib/base/jquery.textmodule.js +++ b/app/assets/javascripts/app/lib/base/jquery.textmodule.js @@ -43,7 +43,9 @@ Plugin.prototype.bindEvents = function () { this.$element.on('keydown', this.onKeydown.bind(this)) - this.$element.on('keypress', this.onKeypress.bind(this)) + // using onInput event to trigger onKeyPress behavior + // since keyPress doesn't work on Mobile Chrome / Android + this.$element.on('input', this.onKeypress.bind(this)) this.$element.on('focus', this.onFocus.bind(this)) } @@ -151,6 +153,16 @@ Plugin.prototype.onKeypress = function (e) { this.log('BUFF', this.buffer, e.keyCode, String.fromCharCode(e.which)) + // gets the character and keycode from event + // this event does not have keyCode and which value set + // so we take char and set those values to not break the flow + // if originalEvent.data is null that means a non char key is pressed like delete, space + if(e.originalEvent && e.originalEvent.data) { + var char = e.originalEvent.data; + var keyCode = char.charCodeAt(0); + e.keyCode = e.which = keyCode; + } + // shift if (e.keyCode === 16) return