bleakgrey / tootle

GTK-based Mastodon client for Linux
GNU General Public License v3.0
400 stars 61 forks source link

Tootle counts bytes instead characters, which is incorrect. #198

Closed veer66 closed 4 years ago

veer66 commented 4 years ago

What should happen: In tooting window, after typing one character, i.e., ก, the counter should show 499.

What happened instead: In tooting window, after typing one character, i.e., ก, the counter should show 497.

How to reproduce: Steps to reproduce the behavior:

  1. Click at pencil icon
  2. In textbox, type ก

Screenshots:

image

Build context:

thep commented 4 years ago

Use string char_count() instead of length?

Index: tootle-0.2.0/src/Dialogs/PostDialog.vala
===================================================================
--- tootle-0.2.0.orig/src/Dialogs/PostDialog.vala
+++ tootle-0.2.0/src/Dialogs/PostDialog.vala
@@ -168,9 +168,9 @@ public class Tootle.PostDialog : Gtk.Dia
     }

     private void validate () {
-        var remain = char_limit - text.buffer.text.length;
+        var remain = char_limit - text.buffer.text.char_count();
         if (spoiler.active)
-            remain -= spoiler_text.buffer.text.length;
+            remain -= spoiler_text.buffer.text.char_count();

         counter.label = remain.to_string ();
         publish.sensitive = remain >= 0;