From 309ca67853b35f3f652686dbb52ca5182b81d0a7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 4 Oct 2019 21:34:41 +0200 Subject: Implement which_run() --- libstorycode/gtk/gtknarrativeview.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'libstorycode/gtk') diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index b7571f1..e44d25b 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -800,22 +800,16 @@ static void insert_text_in_paragraph(struct narrative_item *item, size_t offs, { char *n; int run; - size_t pos; + size_t run_offs; - pos = 0; - for ( run=0; runn_runs; run++ ) { - size_t npos = pos + strlen(item->runs[run].text); - if ( npos >= offs ) break; - pos = npos; - } - offs -= pos; + run = which_run(item, offs, &run_offs); n = malloc(strlen(t) + strlen(item->runs[run].text) + 1); if ( n == NULL ) return; - strncpy(n, item->runs[run].text, offs); - n[offs] = '\0'; + strncpy(n, item->runs[run].text, run_offs); + n[run_offs] = '\0'; strcat(n, t); - strcat(n, item->runs[run].text+offs); + strcat(n, item->runs[run].text+run_offs); free(item->runs[run].text); item->runs[run].text = n; } -- cgit v1.2.3