diff options
author | Thomas White <taw@physics.org> | 2019-10-05 09:58:38 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-10-05 17:03:43 +0200 |
commit | 87f9b270e9b34f5e67ef7897aacca44b608bb408 (patch) | |
tree | 2f58517df344f9c46b054e4e9c6dbee1de0020c4 /libstorycode/narrative.c | |
parent | 309ca67853b35f3f652686dbb52ca5182b81d0a7 (diff) |
Restore paragraph splitting
Diffstat (limited to 'libstorycode/narrative.c')
-rw-r--r-- | libstorycode/narrative.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c index 08c19d3..895f530 100644 --- a/libstorycode/narrative.c +++ b/libstorycode/narrative.c @@ -422,26 +422,42 @@ int which_run(struct narrative_item *item, size_t item_offs, size_t *run_offs) return run; } - void narrative_split_item(Narrative *n, int i1, size_t o1) { - /* FIXME! */ -#if 0 struct narrative_item *item1; struct narrative_item *item2; - item1 = &n->items[i1]; item2 = insert_item(n, i1+1); + item1 = &n->items[i1]; /* NB n->items was realloced by insert_item */ + item2->type = NARRATIVE_ITEM_TEXT; if ( narrative_item_is_text(n, i1) ) { - item2->text = strdup(&item1->text[o1]); - item1->text[o1] = '\0'; + + size_t run_offs; + int run = which_run(item1, o1, &run_offs); + int j; + + item2->n_runs = item1->n_runs - run; + item2->runs = malloc(item2->n_runs*sizeof(struct text_run)); + for ( j=run; j<item1->n_runs; j++ ) { + item2->runs[j-run] = item1->runs[j]; + } + + /* Now break the run */ + item2->runs[0].text = strdup(item1->runs[run].text+run_offs); + item1->runs[run].text[run_offs] = '\0'; + item1->n_runs = run + 1; + } else { - item2->text = strdup(""); - } - item2->type = NARRATIVE_ITEM_TEXT; -#endif + /* Splitting a non-text run simply means creating a new + * plain text item after it */ + item2->runs = malloc(sizeof(struct text_run)); + item2->n_runs = 1; + item2->runs[0].text = strdup(""); + item2->runs[0].type = TEXT_RUN_NORMAL;; + + } } |