84d344c
=== modified file 'terminatorlib/terminal.py'
84d344c
--- terminatorlib/terminal.py	2019-10-21 21:36:16 +0000
84d344c
+++ terminatorlib/terminal.py	2019-11-15 19:47:49 +0000
84d344c
@@ -1093,30 +1093,35 @@
84d344c
         dbg('drag data received of type: %s' % (selection_data.get_data_type()))
84d344c
         if Gtk.targets_include_text(drag_context.list_targets()) or \
84d344c
            Gtk.targets_include_uri(drag_context.list_targets()):
84d344c
-            # copy text with no modification yet to destination
84d344c
-            txt = selection_data.get_data()
84d344c
 
84d344c
-            # https://bugs.launchpad.net/terminator/+bug/1518705
84d344c
             if info == self.TARGET_TYPE_MOZ:
84d344c
-                 txt = txt.decode('utf-16').encode('utf-8')
84d344c
-                 txt = txt.split('\n')[0]
84d344c
-
84d344c
-            txt_lines = txt.split( "\r\n" )
84d344c
-            if txt_lines[-1] == '':
84d344c
-                for line in txt_lines[:-1]:
84d344c
-                    if line[0:7] != 'file://':
84d344c
-                        txt = txt.replace('\r\n','\n')
84d344c
-                        break
84d344c
-                else:
84d344c
-                    # It is a list of crlf terminated file:// URL. let's
84d344c
-                    # iterate over all elements except the last one.
84d344c
-                    str=''
84d344c
-                    for fname in txt_lines[:-1]:
84d344c
-                        dbg('drag data fname: %s' % fname)
84d344c
-                        fname = "'%s'" % urllib.parse.unquote(fname[7:].replace("'",
84d344c
-                                                                    '\'\\\'\''))
84d344c
-                        str += fname + ' '
84d344c
-                    txt=str
84d344c
+                # TYPE_MOZ is two lines encoded in UTF-16: the URL and the visible text. Ignore the latter.
84d344c
+                # https://bugs.launchpad.net/terminator/+bug/1518705
84d344c
+                txt = selection_data.get_data().decode('utf-16')
84d344c
+                txt = txt.split('\n')[0]
84d344c
+            else:
84d344c
+                # Other types are encoded in UTF-8.
84d344c
+                txt = selection_data.get_data().decode()
84d344c
+
84d344c
+                # File managers send CRLF terminated list of filenames.
84d344c
+                # Convert them to space separated, quoted for shell command line.
84d344c
+                txt_lines = txt.split( "\r\n" )
84d344c
+                if txt_lines[-1] == '':
84d344c
+                    for line in txt_lines[:-1]:
84d344c
+                        if line[0:7] != 'file://':
84d344c
+                            txt = txt.replace('\r\n', '\n')
84d344c
+                            break
84d344c
+                    else:
84d344c
+                        # It is a list of crlf terminated file:// URL. Let's
84d344c
+                        # iterate over all elements except the last one.
84d344c
+                        str = ''
84d344c
+                        for fname in txt_lines[:-1]:
84d344c
+                            dbg('drag data fname: %s' % fname)
84d344c
+                            fname = "'%s'" % urllib.parse.unquote(fname[7:].replace("'",
84d344c
+                                                                                    '\'\\\'\''))
84d344c
+                            str += fname + ' '
84d344c
+                        txt = str
84d344c
+
84d344c
             for term in self.terminator.get_target_terms(self):
84d344c
                 term.feed(txt)
84d344c
             return
84d344c
@@ -1513,7 +1518,8 @@
84d344c
 
84d344c
     def feed(self, text):
84d344c
         """Feed the supplied text to VTE"""
84d344c
-        self.vte.feed_child(text, len(text))
84d344c
+        # See https://gitlab.gnome.org/GNOME/vte/issues/201.
84d344c
+        self.vte.feed_child_binary(text.encode(self.vte.get_encoding()))
84d344c
 
84d344c
     def zoom_in(self):
84d344c
         """Increase the font size"""
84d344c