Skip to content

Commit 4b6f365

Browse files
committed
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.
1 parent 9d35ffe commit 4b6f365

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

meld/sourceview.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ def do_paste_clipboard(self, *args):
170170
# contain GtkTextTags, by requesting and setting plain text.
171171

172172
def text_received_cb(clipboard, text, *user_data):
173-
clipboard.set_text(text, len(text))
173+
# Manual encoding is required here, or the length will be
174+
# incorrect, and the API requires a UTF-8 bytestring.
175+
utf8_text = text.encode('utf-8')
176+
clipboard.set_text(text, len(utf8_text))
174177
self.get_buffer().paste_clipboard(
175178
clipboard, None, self.get_editable())
176179

0 commit comments

Comments
 (0)