Commits

Anonymous committed 778b2ea

fix 80-char limiting of utf-8 encoded strings

The limit was applied to the native encoded string, which not only calculates the wrong
length but also makes GTK crash badly if a code point is cut in half, when the native
encoding was UTF-8.

Comments (0)

Files changed (4)

tortoisehg/hgtk/changeset.py

             return gtklib.markup(revid, **opts)
         def data_func(widget, item, ctx):
             def summary_line(desc):
-                desc = desc.replace('\0', '')
-                return hglib.toutf(desc.split('\n')[0][:80])
+                desc = hglib.tounicode(desc.replace('\0', '').split('\n')[0])
+                return hglib.toutf(desc[:80])
             def revline_data(ctx, hl=False, branch=None):
                 if isinstance(ctx, basestring):
                     return ctx

tortoisehg/hgtk/commit.py

             self.msg_config(None)
             return False
         
-        lines = buf.get_text(buf.get_start_iter(),
-                             buf.get_end_iter()).splitlines()
+        lines = hglib.tounicode(buf.get_text(buf.get_start_iter(),
+                                             buf.get_end_iter())).splitlines()
         
         if sumlen and len(lines[0].rstrip()) > sumlen:
             resp = gdialog.Confirm(_('Confirm Commit'), [], self,

tortoisehg/hgtk/csinfo.py

             elif item == 'desc':
                 return hglib.toutf(ctx.description().replace('\0', ''))
             elif item == 'summary':
-                desc = self.get_data('desc', *args)
-                value = desc.split('\n')[0][:80]
+                value = ctx.description().replace('\0', '').split('\n')[0]
+                value = hglib.tounicode(value[:80])
                 if len(value) == 0:
                     return  None
-                return value
+                return hglib.toutf(value)
             elif item == 'user':
                 return hglib.toutf(ctx.user())
             elif item == 'dateage':

tortoisehg/hgtk/hgcmd.py

             self.cmdlist = []
         title = text or ' '.join(cmdline)
         if len(title) > 80:
-            title = title[:80] + '...'
+            title = hglib.tounicode(title)[:80] + '...'
         title = hglib.toutf(title.replace('\n', ' '))
         gtk.Dialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL)
         self.set_has_separator(False)