|
|
60bd5a |
From 8e1c0af770837ce9972b7024160d8880bfdc2c01 Mon Sep 17 00:00:00 2001
|
|
|
60bd5a |
From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= <mcepl@redhat.com>
|
|
|
60bd5a |
Date: Sun, 15 Dec 2013 23:41:30 +0100
|
|
|
60bd5a |
Subject: [PATCH 1/2] iter.get_char() returns bytes of UTF-8 encoded text.
|
|
|
60bd5a |
MIME-Version: 1.0
|
|
|
60bd5a |
Content-Type: text/plain; charset=UTF-8
|
|
|
60bd5a |
Content-Transfer-Encoding: 8bit
|
|
|
60bd5a |
|
|
|
60bd5a |
Make shell function which returns always one character long string,
|
|
|
60bd5a |
either bytes() or unicode() (using py3k terminology).
|
|
|
60bd5a |
|
|
|
60bd5a |
Fixes BGO# 720324
|
|
|
60bd5a |
|
|
|
60bd5a |
Signed-off-by: Matěj Cepl <mcepl@redhat.com>
|
|
|
60bd5a |
---
|
|
|
60bd5a |
plugins/joinlines/joinlines.py | 31 ++++++++++++++++++++-----------
|
|
|
60bd5a |
1 file changed, 20 insertions(+), 11 deletions(-)
|
|
|
60bd5a |
|
|
|
60bd5a |
--- a/plugins/joinlines/joinlines.py
|
|
|
60bd5a |
+++ b/plugins/joinlines/joinlines.py
|
|
|
60bd5a |
@@ -30,6 +30,13 @@ except:
|
|
|
60bd5a |
_ = lambda s: s
|
|
|
60bd5a |
|
|
|
60bd5a |
|
|
|
60bd5a |
+def iter_get_char(iter):
|
|
|
60bd5a |
+ char = iter.get_char()
|
|
|
60bd5a |
+ if len(char) > 1:
|
|
|
60bd5a |
+ char = char.decode('utf8')
|
|
|
60bd5a |
+ return char
|
|
|
60bd5a |
+
|
|
|
60bd5a |
+
|
|
|
60bd5a |
class JoinLinesAppActivatable(GObject.Object, Gedit.AppActivatable):
|
|
|
60bd5a |
app = GObject.property(type=Gedit.App)
|
|
|
60bd5a |
|
|
|
60bd5a |
@@ -138,13 +145,13 @@ class JoinLinesViewActivatable(GObject.O
|
|
|
60bd5a |
start.forward_to_line_end()
|
|
|
60bd5a |
|
|
|
60bd5a |
# Include trailing spaces in the chunk to be removed
|
|
|
60bd5a |
- while start.backward_char() and start.get_char() in ('\t', ' '):
|
|
|
60bd5a |
+ while start.backward_char() and iter_get_char(start) in ('\t', ' '):
|
|
|
60bd5a |
pass
|
|
|
60bd5a |
start.forward_char()
|
|
|
60bd5a |
|
|
|
60bd5a |
while doc.get_iter_at_mark(end_mark).compare(start) == 1:
|
|
|
60bd5a |
end = start.copy()
|
|
|
60bd5a |
- while end.get_char() in ('\r', '\n', ' ', '\t'):
|
|
|
60bd5a |
+ while iter_get_char(end) in ('\r', '\n', ' ', '\t'):
|
|
|
60bd5a |
end.forward_char()
|
|
|
60bd5a |
doc.delete(start, end)
|
|
|
60bd5a |
|
|
|
60bd5a |
@@ -173,7 +180,7 @@ class JoinLinesViewActivatable(GObject.O
|
|
|
60bd5a |
indent_iter.set_line_offset(0)
|
|
|
60bd5a |
indent = ''
|
|
|
60bd5a |
while indent_iter.get_offset() != start.get_offset():
|
|
|
60bd5a |
- if indent_iter.get_char() == '\t':
|
|
|
60bd5a |
+ if iter_get_char(indent_iter) == '\t':
|
|
|
60bd5a |
indent = indent + '\t'
|
|
|
60bd5a |
else:
|
|
|
60bd5a |
indent = indent + ' '
|
|
|
60bd5a |
@@ -189,8 +196,8 @@ class JoinLinesViewActivatable(GObject.O
|
|
|
60bd5a |
# measure indent of line
|
|
|
60bd5a |
indent_iter = start.copy()
|
|
|
60bd5a |
indent = ''
|
|
|
60bd5a |
- while indent_iter.get_char() in (' ', '\t'):
|
|
|
60bd5a |
- indent = indent + indent_iter.get_char()
|
|
|
60bd5a |
+ while iter_get_char(indent_iter) in (' ', '\t'):
|
|
|
60bd5a |
+ indent = indent + iter_get_char(indent_iter)
|
|
|
60bd5a |
indent_iter.forward_char()
|
|
|
60bd5a |
|
|
|
60bd5a |
end_mark = doc.create_mark(None, end)
|
|
|
60bd5a |
@@ -231,16 +238,16 @@ class JoinLinesViewActivatable(GObject.O
|
|
|
60bd5a |
|
|
|
60bd5a |
|
|
|
60bd5a |
def forward_to_word_start(text_iter):
|
|
|
60bd5a |
- char = text_iter.get_char()
|
|
|
60bd5a |
+ char = iter_get_char(text_iter)
|
|
|
60bd5a |
while not text_iter.is_end() and char in (' ', '\t', '\n', '\r'):
|
|
|
60bd5a |
text_iter.forward_char()
|
|
|
60bd5a |
- char = text_iter.get_char()
|
|
|
60bd5a |
+ char = iter_get_char(text_iter)
|
|
|
60bd5a |
|
|
|
60bd5a |
|
|
|
60bd5a |
def forward_to_word_end(text_iter):
|
|
|
60bd5a |
- char = text_iter.get_char()
|
|
|
60bd5a |
+ char = iter_get_char(text_iter)
|
|
|
60bd5a |
while not text_iter.is_end() and not (char in (' ', '\t', '\n', '\r')):
|
|
|
60bd5a |
text_iter.forward_char()
|
|
|
60bd5a |
- char = text_iter.get_char()
|
|
|
60bd5a |
+ char = iter_get_char(text_iter)
|
|
|
60bd5a |
|
|
|
60bd5a |
# ex:ts=4:et:
|