URI: 
       tFix wrapping again - ltkx - GUI toolkit for X11 (WIP)
  HTML git clone git://lumidify.org/ltkx.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 288e467a6083a547a3996e69b6ba0ea1d430e70b
   DIR parent 8db8f0b44f5f1c727be32114a22863bf72355a76
  HTML Author: lumidify <nobody@lumidify.org>
       Date:   Tue, 26 May 2020 11:23:50 +0200
       
       Fix wrapping again
       
       Diffstat:
         M text_buffer.c                       |      16 +++++++++++-----
         M text_edit.c                         |       1 +
       
       2 files changed, 12 insertions(+), 5 deletions(-)
       ---
   DIR diff --git a/text_buffer.c b/text_buffer.c
       t@@ -77,7 +77,6 @@ ltk_text_line_cleanup_soft_lines(struct ltk_array_line *soft_lines, int old_len)
                ltk_array_resize_line(soft_lines, soft_lines->len);
        }
        
       -/* FIXME: this is a few pixels off! */
        void
        ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
                struct timeval t1, t2;
       t@@ -126,6 +125,10 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
                        if (cur->dir == HB_DIRECTION_RTL) {
                                cur_start = cur->glyphs[cur->num_glyphs - 1].x_abs + cur->glyphs[cur->num_glyphs - 1].x_advance;
                                int i = cur->num_glyphs - 1;
       +                        /* This is needed to properly break a run over multiple lines.
       +                           We can't just reuse sl->glyph_index because that might be
       +                           located in another run */
       +                        int cur_start_index = cur->num_glyphs - 1;
                                while (i >= 0) {
                                        glyph = &cur->glyphs[i];
                                        int cur_w = sl->w + cur_start - glyph->x_abs;
       t@@ -135,8 +138,8 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
                                                        if (char_break == -1 && cur->glyphs[j].cluster != glyph->cluster)
                                                                char_break = j;
                                                        if ((j != i && tl->log_buf->buf[cur->glyphs[j].cluster] == 0x20) ||
       -                                                    j == cur->num_glyphs - 1 || sl->len == 0) {
       -                                                        if (j == cur->num_glyphs - 1 &&
       +                                                    j == cur_start_index || sl->len == 0) {
       +                                                        if (j == cur_start_index &&
                                                                    tl->log_buf->buf[cur->glyphs[j].cluster] != 0x20) {
                                                                        if (sl->len == 0) {
                                                                                char_break = char_break == -1 ? j : char_break;
       t@@ -159,6 +162,7 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
                                                                    tl->soft_lines->buf[cur_index] :
                                                                    ltk_soft_line_create();
                                                                sl->glyph_index = i;
       +                                                        cur_start_index = i;
                                                                sl->run = cur;
                                                                sl->len = 0;
                                                                sl->w = 0;
       t@@ -180,6 +184,7 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
                        } else {
                                cur_start = cur->glyphs[0].x_abs;
                                int i = 0;
       +                        int cur_start_index = 0;
                                while (i < cur->num_glyphs) {
                                        glyph = &cur->glyphs[i];
                                        /* FIXME: This uses x_advance instead of glyph width so it works correctly
       t@@ -192,8 +197,8 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
                                                        if (char_break == -1 && cur->glyphs[j].cluster != glyph->cluster)
                                                                char_break = j;
                                                        if ((j != i && tl->log_buf->buf[cur->glyphs[j].cluster] == 0x20) ||
       -                                                    j == 0 || sl->len == 0) {
       -                                                        if (j == 0 &&
       +                                                    j == cur_start_index || sl->len == 0) {
       +                                                        if (j == cur_start_index &&
                                                                    tl->log_buf->buf[cur->glyphs[j].cluster] != 0x20) {
                                                                        if (sl->len == 0) {
                                                                                char_break = char_break == -1 ? j : char_break;
       t@@ -216,6 +221,7 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
                                                                    tl->soft_lines->buf[cur_index] :
                                                                    ltk_soft_line_create();
                                                                sl->glyph_index = i;
       +                                                        cur_start_index = i;
                                                                sl->run = cur;
                                                                sl->len = 0;
                                                                sl->w = 0;
   DIR diff --git a/text_edit.c b/text_edit.c
       t@@ -61,6 +61,7 @@ ltk_text_edit_draw(LtkTextEdit *te) {
                );
        }
        
       +/* FIXME: only recalculate if largest line is too wide */
        void
        ltk_text_edit_resize(LtkTextEdit *te, int orig_w, int orig_h) {
                if (te->tl->soft_lines->len == 1 &&