summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIván Sánchez Ortega <ivan.sanchez@collabora.com>2019-05-02 09:28:55 +0200
committerAndras Timar <andras.timar@collabora.com>2019-05-03 13:53:02 +0200
commit3a30ac379948dfc903883cd2549103d6126b7784 (patch)
treefdcbbbad9152bbbb49bb52ae8ce37e7e10a6049b
parent6e96d5da1d55aafe0c5e581998723c727a0ffe39 (diff)
tdf#124749:loleaflet: use "KeyboardEvent.key" to detect ignored key events
Replace KeyboardEvent.keyCode with KeyboardEvent.key for detection of "Delete" and "Insert" keys. keyCode misbehaves when using an AZERTY/DVORAK keyboard layout, e.g. the keyCode for "Delete" in QWERTY is the same as "." in AZERTY. This works on all major browsers, the only outlier being MSIE8: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#Browser_compatibility Change-Id: I5cbfa18ef59ab4989a866fdf4b5708610beccaad Reviewed-on: https://gerrit.libreoffice.org/71735 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--loleaflet/src/map/handler/Map.Keyboard.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index 28144cc53..863473bae 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -182,16 +182,23 @@ L.Map.Keyboard = L.Handler.extend({
this._map.off('compositionstart compositionupdate compositionend textInput', this._onIME, this);
},
+ /*
+ * Returns true whenever the key event shall be ignored.
+ * This means shift+insert and shift+delete (or "insert or delete when holding
+ * shift down"). Those events are handled elsewhere to trigger "cut" and
+ * "paste" events, and need to be ignored in order to avoid double-handling them.
+ */
_ignoreKeyEvent: function(e) {
- var shift = e.originalEvent.shiftKey ? this.keyModifier.shift : 0;
- if (shift && (e.originalEvent.keyCode === 45 || e.originalEvent.keyCode === 46)) {
- // don't handle shift+insert, shift+delete
- // These are converted to 'cut', 'paste' events which are
- // automatically handled by us, so avoid double-handling
- return true;
+ var shift = e.originalEvent.shiftKey;
+ if ('key' in e.originalEvent) {
+ var key = e.originalEvent.key;
+ return (shift && (key === 'Delete' || key === 'Insert'));
+ } else {
+ // keyCode is not reliable in AZERTY/DVORAK keyboard layouts, is used
+ // only as a fallback for MSIE8.
+ var keyCode = e.originalEvent.keyCode;
+ return (shift && (keyCode === 45 || keyCode === 46));
}
-
- return false;
},
_setPanOffset: function (pan) {