[polari] entryArea: Intercept ::insert-text instead of ::drag-data-received



commit 3dedb3b18a88ebcfecff665f714713bbf948d66f
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Aug 24 16:23:26 2021 +0200

    entryArea: Intercept ::insert-text instead of ::drag-data-received
    
    Waiting until the received text is inserted into the entry before
    intercepting GTK's built-in handling allows us to handle paste
    service integration in the common code path between clipboard and
    drop target.
    
    Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/225>

 src/entryArea.js | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
---
diff --git a/src/entryArea.js b/src/entryArea.js
index 1714f9fe..b8193779 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -40,8 +40,7 @@ export const ChatEntry = GObject.registerClass({
                 this.emit('insert-emoji');
         });
 
-        this._useDefaultHandler = false;
-
+        this.connect('insert-text', this._onInsertText.bind(this));
         this.connect('paste-clipboard', this._onPasteClipboard.bind(this));
     }
 
@@ -50,18 +49,17 @@ export const ChatEntry = GObject.registerClass({
         return true;
     }
 
-    vfunc_drag_data_received(context, x, y, data, info, time) {
-        let str = data.get_text();
-        if (!str || str.split('\n').length >= MAX_LINES)
-            // Disable GtkEntry's built-in drop target support
+    _onInsertText(editable, text) {
+        const nLines = text.split('\n').length;
+        if (nLines < MAX_LINES)
             return;
 
-        GObject.signal_stop_emission_by_name(this, 'drag-data-received');
-        super.vfunc_drag_data_received(context, x, y, data, info, time);
+        editable.stop_emission_by_name('insert-text');
+        this.emit('text-pasted', text, nLines);
     }
 
     _onPasteClipboard(editable) {
-        if (!this.editable || this._useDefaultHandler)
+        if (!this.editable)
             return;
 
         editable.stop_emission_by_name('paste-clipboard');
@@ -84,17 +82,7 @@ export const ChatEntry = GObject.registerClass({
     _onTextReceived(clipboard, text) {
         if (!text)
             return;
-        text = text.trim();
-
-        let nLines = text.split('\n').length;
-        if (nLines >= MAX_LINES) {
-            this.emit('text-pasted', text, nLines);
-            return;
-        }
-
-        this._useDefaultHandler = true;
-        this.emit('paste-clipboard');
-        this._useDefaultHandler = false;
+        this.emit('insert-at-cursor', text);
     }
 });
 


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