Fix run determination when inserting text
authorThomas White <taw@physics.org>
Thu, 3 Oct 2019 20:20:05 +0000 (22:20 +0200)
committerThomas White <taw@physics.org>
Sat, 5 Oct 2019 15:03:43 +0000 (17:03 +0200)
libstorycode/gtk/gtknarrativeview.c

index bb549d4..b7571f1 100644 (file)
@@ -804,8 +804,9 @@ static void insert_text_in_paragraph(struct narrative_item *item, size_t offs,
 
        pos = 0;
        for ( run=0; run<item->n_runs; run++ ) {
-               pos += strlen(item->runs[run].text);
-               if ( pos > offs ) break;
+               size_t npos = pos + strlen(item->runs[run].text);
+               if ( npos >= offs ) break;
+               pos = npos;
        }
        offs -= pos;