mirror of https://github.com/zulip/zulip.git
typeahead: Patch third/typeahead.js for IME event handling.
We do not want to import any of our modules into this file, so it has an independent implementation of the fix for #22062. Also, using -13 as a keyCode helps avoid having to make changes to all the comparisons with e.keyCode that the module relies on.
This commit is contained in:
parent
e5c26eeb86
commit
103b8f6de3
|
@ -71,15 +71,30 @@
|
|||
* Our custom changes include all mentions of `helpOnEmptyStrings` and `hideOnEmpty`.
|
||||
*
|
||||
* 6. Prevent typeahead going off top of screen:
|
||||
*
|
||||
* If typeahead would go off the top of the screen, we set its top to 0 instead.
|
||||
* This patch should be replaced with something more flexible.
|
||||
*
|
||||
* 7. Ignore IME Enter events:
|
||||
*
|
||||
* See #22062 for details. Enter keypress that are part of IME composing are
|
||||
* treated as a separate/invalid -13 key, to prevent them from being incorrectly
|
||||
* processed as a bonus Enter press.
|
||||
*
|
||||
* ============================================================ */
|
||||
|
||||
!function($){
|
||||
|
||||
"use strict"; // jshint ;_;
|
||||
|
||||
function get_pseudo_keycode(e) {
|
||||
const isComposing = (event.originalEvent && event.originalEvent.isComposing) || false;
|
||||
/* We treat IME compose enter keypresses as a separate -13 key. */
|
||||
if (e.keyCode === 13 && isComposing) {
|
||||
return -13;
|
||||
}
|
||||
return e.keyCode;
|
||||
}
|
||||
|
||||
/* TYPEAHEAD PUBLIC CLASS DEFINITION
|
||||
* ================================= */
|
||||
|
@ -354,8 +369,9 @@
|
|||
|
||||
, move: function (e) {
|
||||
if (!this.shown) return
|
||||
const pseudo_keycode = get_pseudo_keycode(e);
|
||||
|
||||
switch(e.keyCode) {
|
||||
switch(pseudo_keycode) {
|
||||
case 9: // tab
|
||||
case 13: // enter
|
||||
case 27: // escape
|
||||
|
@ -373,7 +389,7 @@
|
|||
break
|
||||
}
|
||||
|
||||
if ((this.options.stopAdvance || (e.keyCode != 9 && e.keyCode != 13))
|
||||
if ((this.options.stopAdvance || (pseudo_keycode != 9 && pseudo_keycode != 13))
|
||||
&& $.inArray(e.keyCode, this.options.advanceKeyCodes)) {
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
@ -389,12 +405,13 @@
|
|||
}
|
||||
|
||||
, keydown: function (e) {
|
||||
const pseudo_keycode = get_pseudo_keycode(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.suppressKeyPressRepeat = !~$.inArray(pseudo_keycode, [40,38,9,13,27]);
|
||||
this.move(e)
|
||||
}
|
||||
|
||||
|
@ -404,7 +421,9 @@
|
|||
}
|
||||
|
||||
, keyup: function (e) {
|
||||
switch(e.keyCode) {
|
||||
const pseudo_keycode = get_pseudo_keycode(e);
|
||||
|
||||
switch(pseudo_keycode) {
|
||||
case 40: // down arrow
|
||||
case 38: // up arrow
|
||||
break
|
||||
|
@ -431,7 +450,7 @@
|
|||
this.lookup(hideOnEmpty)
|
||||
}
|
||||
|
||||
if ((this.options.stopAdvance || (e.keyCode != 9 && e.keyCode != 13))
|
||||
if ((this.options.stopAdvance || (pseudo_keycode != 9 && pseudo_keycode != 13))
|
||||
&& $.inArray(e.keyCode, this.options.advanceKeyCodes)) {
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue