From 38abc5ca9134ea0b19164392488f5cbc1ddff00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCl=C5=9Fah=20K=C3=B6se?= Date: Fri, 7 Oct 2022 12:13:38 +0300 Subject: [PATCH] Add percentage sign to cell automatically. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gülşah Köse Change-Id: I422f63c6d3963bdf125fc00e7dafc4428883c7ce --- browser/src/layer/marker/TextInput.js | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/browser/src/layer/marker/TextInput.js b/browser/src/layer/marker/TextInput.js index 5beed3c6b..6d3081f1e 100644 --- a/browser/src/layer/marker/TextInput.js +++ b/browser/src/layer/marker/TextInput.js @@ -79,6 +79,21 @@ L.TextInput = L.Layer.extend({ '?': [ 63, 0, 0, 4287 ], '_': [ 95, 0, 0, 5384 ] }; + + // unoKeyCode values of the digits. + this._unoKeyMap = { + '48': 96, // 0 + '49': 97, // 1 + '50': 98, // 2 + '51': 99, // 3 + '52': 100, // 4 + '53': 101, // 5 + '54': 102, // 6 + '55': 103, // 7 + '56': 104, // 8 + '57': 105 // 9 + }; + }, onAdd: function() { @@ -563,6 +578,12 @@ L.TextInput = L.Layer.extend({ this._lastContent = oldContent; }, + _isDigit: function(asciiChar) { + if (asciiChar >= 48 && asciiChar <= 57) + return true; + return false; + }, + // Fired when text has been inputed, *during* and after composing/spellchecking _onInput: function(ev) { if (this._map.uiManager.isUIBlocked()) @@ -680,7 +701,15 @@ L.TextInput = L.Layer.extend({ this._lastContent = content; if (newText.length > 0) { - this._sendText(this.codePointsToString(newText)); + // When the cell formatted as percent, to trig percentage sign addition + // automatically we send the first digit character as KeyEvent. + if (this._map.getDocType() === 'spreadsheet' && + content.length === 1 && ev.inputType === 'insertText' && + this._isDigit(newText)) { + this._sendKeyEvent(newText, this._unoKeyMap[newText], 'input'); + } + else + this._sendText(this.codePointsToString(newText)); } // was a 'delete' and we need to reset world.