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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Jul 29 19:04:31 UTC 2018


 loleaflet/src/map/handler/Map.Keyboard.js |  108 +++++++++++++-----------------
 1 file changed, 49 insertions(+), 59 deletions(-)

New commits:
commit 42823fcafb89bb854036fe09bbc6281ac50189c9
Author:     Henry Castro <hcastro at collabora.com>
AuthorDate: Sun Jul 29 15:01:10 2018 -0400
Commit:     Henry Castro <hcastro at collabora.com>
CommitDate: Sun Jul 29 15:03:57 2018 -0400

    loleaflet: mobile: fix delete with backspace
    
    Change-Id: I36eddf8b81849592982d01f3a4c7f3be0f0c0ee3

diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index 16d31528f..9e1bad2ca 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -173,13 +173,13 @@ L.Map.Keyboard = L.Handler.extend({
 
 		this._map.on('mousedown', this._onMouseDown, this);
 		this._map.on('keydown keyup keypress', this._onKeyDown, this);
-		this._map.on('compositionstart compositionupdate compositionend textInput', this._onKeyDown, this);
+		this._map.on('compositionstart compositionupdate compositionend textInput', this._onIME, this);
 	},
 
 	removeHooks: function () {
 		this._map.off('mousedown', this._onMouseDown, this);
 		this._map.off('keydown keyup keypress', this._onKeyDown, this);
-		this._map.off('compositionstart compositionupdate compositionend textInput', this._onKeyDown, this);
+		this._map.off('compositionstart compositionupdate compositionend textInput', this._onIME, this);
 	},
 
 	_ignoreKeyEvent: function(e) {
@@ -296,25 +296,6 @@ L.Map.Keyboard = L.Handler.extend({
 		var charCode = e.originalEvent.charCode;
 		var keyCode = e.originalEvent.keyCode;
 
-		if (e.type === 'compositionstart' || e.type === 'compositionupdate') {
-			this._isComposing = true; // we are starting composing with IME
-			var txt = '';
-			for (var i = 0; i < e.originalEvent.data.length; i++) {
-				txt += e.originalEvent.data[i];
-			}
-			if (txt) {
-				compEventFn('input', txt);
-			}
-		}
-
-		if (e.type === 'compositionend') {
-			this._isComposing = false; // stop of composing with IME
-			// get the composited char codes
-			// clear the input now - best to do this ASAP so the input
-			// is clear for the next word
-			inputEle.value = '';
-		}
-
 		if (!this._isComposing && e.type === 'keyup') {
 			// not compositing and keyup, clear the input so it is ready
 			// for next word (or char only)
@@ -340,14 +321,12 @@ L.Map.Keyboard = L.Handler.extend({
 			}
 			else if (e.type === 'keydown') {
 				this._keyHandled = false;
-				this._bufferedTextInputEvent = null;
 
 				if (this.handleOnKeyDownKeys[keyCode] && charCode === 0) {
 					keyEventFn('input', charCode, unoKeyCode);
 				}
 			}
-			else if ((e.type === 'keypress' || e.type === 'compositionend') &&
-			         (!this.handleOnKeyDownKeys[keyCode] || charCode !== 0)) {
+			else if ((e.type === 'keypress') && (!this.handleOnKeyDownKeys[keyCode] || charCode !== 0)) {
 				if (charCode === keyCode && charCode !== 13) {
 					// Chrome sets keyCode = charCode for printable keys
 					// while LO requires it to be 0
@@ -358,47 +337,13 @@ L.Map.Keyboard = L.Handler.extend({
 					// key press times will be paired with the invalidation messages
 					docLayer._debugKeypressQueue.push(+new Date());
 				}
-				if (e.type === 'compositionend') {
-					// Set all keycodes to zero
-					compEventFn('end', '');
-				} else {
-					keyEventFn('input', charCode, unoKeyCode);
-				}
 
+				keyEventFn('input', charCode, unoKeyCode);
 				this._keyHandled = true;
 			}
-			else if (e.type === 'textInput') {
-				// Store the textInput event
-				this._bufferedTextInputEvent = e;
-			}
 			else if (e.type === 'keyup') {
-				// Hack for making space and spell-check text insert work
-				// in Chrome (on Andorid) or Chrome with IME.
-				//
-				// Chrome (Android) IME triggers keyup/keydown input with
-				// code 229 when hitting space (as with all composiiton events)
-				// with addition to 'textinput' event, in which we only see that
-				// space was entered. Similar situation is also when inserting
-				// a soft-keyboard spell-check item - it is visible only with
-				// 'textinput' event (no composition event is fired).
-				// To make this work we need to insert textinput.data here..
-				//
-				// TODO: Maybe make sure this is only triggered when keydown has
-				// 229 code. Also we need to detect that composition was overriden
-				// (part or whole word deleted) with the spell-checked word. (for
-				// example: enter 'tar' and with spell-check correct that to 'rat')
-
-				if (!this._keyHandled && this._bufferedTextInputEvent) {
-					var textInputData = this._bufferedTextInputEvent.originalEvent.data;
-					charCode = e.originalEvent.keyCode;
-					for (var idx = 0; idx < textInputData.length; idx++) {
-						keyEventFn('input', textInputData[idx].charCodeAt(), 0);
-					}
-				}
 				keyEventFn('up', charCode, unoKeyCode);
-
 				this._keyHandled = true;
-				this._bufferedTextInputEvent = null;
 			}
 			if (keyCode === 9) {
 				// tab would change focus to other DOM elements
@@ -431,6 +376,51 @@ L.Map.Keyboard = L.Handler.extend({
 		L.DomEvent.stopPropagation(e.originalEvent);
 	},
 
+	_onIME: function (e) {
+		if (e.type === 'compositionstart' || e.type === 'compositionupdate') {
+			this._isComposing = true; // we are starting composing with IME
+			var txt = '';
+			for (var i = 0; i < e.originalEvent.data.length; i++) {
+				txt += e.originalEvent.data[i];
+			}
+			if (txt) {
+				this._map._docLayer._postCompositionEvent(0, 'input', txt);
+			}
+		}
+
+		if (e.type === 'compositionend') {
+			this._isComposing = false; // stop of composing with IME
+			// get the composited char codes
+			// clear the input now - best to do this ASAP so the input
+			// is clear for the next word
+			this._map._clipboardContainer._textArea.value = '';
+			// Set all keycodes to zero
+			this._map._docLayer._postCompositionEvent(0, 'end', '');
+		}
+
+		if (e.type === 'textInput' && !this._keyHandled) {
+			// Hack for making space and spell-check text insert work
+			// in Chrome (on Andorid) or Chrome with IME.
+			//
+			// Chrome (Android) IME triggers keyup/keydown input with
+			// code 229 when hitting space (as with all composiiton events)
+			// with addition to 'textinput' event, in which we only see that
+			// space was entered. Similar situation is also when inserting
+			// a soft-keyboard spell-check item - it is visible only with
+			// 'textinput' event (no composition event is fired).
+			// To make this work we need to insert textinput.data here..
+			//
+			// TODO: Maybe make sure this is only triggered when keydown has
+			// 229 code. Also we need to detect that composition was overriden
+			// (part or whole word deleted) with the spell-checked word. (for
+			// example: enter 'tar' and with spell-check correct that to 'rat')
+			var data = e.originalEvent.data;
+			for (var idx = 0; idx < data.length; idx++) {
+				this._map._docLayer._postKeyboardEvent('input', data[idx].charCodeAt(), 0);
+			}
+		}
+	},
+
 	_handleCtrlCommand: function (e) {
 		// Control
 		if (e.originalEvent.keyCode == 17)


More information about the Libreoffice-commits mailing list