[meld] sourceview: Fix pasting multi-byte encodings (#179)



commit 4b6f36527396d5016ccbfabfb89efd0695bbaff4
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Apr 26 06:46:59 2018 +1000

    sourceview: Fix pasting multi-byte encodings (#179)
    
    For this API, pygobject isn't handling string length arguments for us,
    so we had to do it ourselves. Shockingly, I got it very wrong. The API
    requires a UTF-8 encoded string (which pygobject transparently encoded
    for us) but the length arg has to be the bytestring length, not the
    unicode codepoint length, which is what we were previously passing
    along.

 meld/sourceview.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/meld/sourceview.py b/meld/sourceview.py
index 5226b527..a2c947ec 100644
--- a/meld/sourceview.py
+++ b/meld/sourceview.py
@@ -170,7 +170,10 @@ class MeldSourceView(GtkSource.View):
         # contain GtkTextTags, by requesting and setting plain text.
 
         def text_received_cb(clipboard, text, *user_data):
-            clipboard.set_text(text, len(text))
+            # Manual encoding is required here, or the length will be
+            # incorrect, and the API requires a UTF-8 bytestring.
+            utf8_text = text.encode('utf-8')
+            clipboard.set_text(text, len(utf8_text))
             self.get_buffer().paste_clipboard(
                 clipboard, None, self.get_editable())
 


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