[Libreoffice-commits] online.git: loleaflet/src

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri May 3 11:53:30 UTC 2019


 loleaflet/src/map/handler/Map.Keyboard.js |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

New commits:
commit e6576f0447d28e4fad7b5bcc2aadede20830caaa
Author:     Iván Sánchez Ortega <ivan.sanchez at collabora.com>
AuthorDate: Thu May 2 09:28:55 2019 +0200
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Fri May 3 13:53:12 2019 +0200

    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/71657
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index 7bd467744..4e3b51354 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) {


More information about the Libreoffice-commits mailing list