[gnome-shell/wip/carlosg/fallback-im-virtual-keys: 1/2] keyboard: Refactor code




commit 524a5401266f8b30c2210cf147530cbb815b71ed
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Oct 11 18:23:19 2022 +0200

    keyboard: Refactor code
    
    Move inline anonymous function to be its own. This method
    will become asynchronous in following commits.

 js/ui/keyboard.js | 54 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 25 deletions(-)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index 895691c34e..28369316e1 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -1510,31 +1510,8 @@ var Keyboard = GObject.registerClass({
                 button.setWidth(key.width);
 
             if (key.action !== 'modifier') {
-                button.connect('commit', (actor, keyval, str) => {
-                    if (this._modifiers.size === 0 && str !== '' &&
-                        keyval && this._oskCompletionEnabled) {
-                        Main.inputMethod.handleVirtualKey(keyval);
-                        return;
-                    }
-
-                    if (str === '' || !Main.inputMethod.currentFocus ||
-                        (keyval && this._oskCompletionEnabled) ||
-                        this._modifiers.size > 0 ||
-                        !this._keyboardController.commitString(str, true)) {
-                        if (keyval !== 0) {
-                            this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS);
-                            this._keyboardController.keyvalPress(keyval);
-                            GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => {
-                                this._keyboardController.keyvalRelease(keyval);
-                                this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE);
-                                this._disableAllModifiers();
-                                return GLib.SOURCE_REMOVE;
-                            });
-                        }
-                    }
-
-                    if (!this._latched)
-                        this._setActiveLayer(0);
+                button.connect('commit', (_actor, keyval, str) => {
+                    this._commitAction(keyval, str);
                 });
             }
 
@@ -1592,6 +1569,33 @@ var Keyboard = GObject.registerClass({
         }
     }
 
+    _commitAction(keyval, str) {
+        if (this._modifiers.size === 0 && str !== '' &&
+            keyval && this._oskCompletionEnabled) {
+            Main.inputMethod.handleVirtualKey(keyval);
+            return;
+        }
+
+        if (str === '' || !Main.inputMethod.currentFocus ||
+            (keyval && this._oskCompletionEnabled) ||
+            this._modifiers.size > 0 ||
+            !this._keyboardController.commitString(str, true)) {
+            if (keyval !== 0) {
+                this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS);
+                this._keyboardController.keyvalPress(keyval);
+                GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => {
+                    this._keyboardController.keyvalRelease(keyval);
+                    this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE);
+                    this._disableAllModifiers();
+                    return GLib.SOURCE_REMOVE;
+                });
+            }
+        }
+
+        if (!this._latched)
+            this._setActiveLayer(0);
+    }
+
     _previousWordPosition(text, cursor) {
         /* Skip word prior to cursor */
         let pos = Math.max(0, text.slice(0, cursor).search(/\s+\S+\s*$/));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]