aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-10-05 09:58:38 +0200
committerThomas White <taw@physics.org>2019-10-05 17:03:43 +0200
commit87f9b270e9b34f5e67ef7897aacca44b608bb408 (patch)
tree2f58517df344f9c46b054e4e9c6dbee1de0020c4
parent309ca67853b35f3f652686dbb52ca5182b81d0a7 (diff)
Restore paragraph splitting
-rw-r--r--libstorycode/gtk/gtknarrativeview.c5
-rw-r--r--libstorycode/narrative.c36
2 files changed, 30 insertions, 11 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c
index e44d25b..897bf97 100644
--- a/libstorycode/gtk/gtknarrativeview.c
+++ b/libstorycode/gtk/gtknarrativeview.c
@@ -832,13 +832,16 @@ static void insert_text(char *t, GtkNarrativeView *e)
if ( strcmp(t, "\n") == 0 ) {
narrative_split_item(e->n, e->cpos.para, off);
rewrap_range(e, e->cpos.para, e->cpos.para+1);
+ e->cpos.para += 1;
+ e->cpos.pos = 0;
+ e->cpos.trail = 0;
} else {
insert_text_in_paragraph(item, off, t);
rewrap_range(e, e->cpos.para, e->cpos.para);
+ cursor_moveh(e->n, &e->cpos, +1);
}
update_size(e);
- cursor_moveh(e->n, &e->cpos, +1);
} /* else do nothing */
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;;
+
+ }
}