Restore slide text insertion
authorThomas White <taw@bitwiz.me.uk>
Thu, 10 Oct 2019 20:34:10 +0000 (22:34 +0200)
committerThomas White <taw@bitwiz.me.uk>
Thu, 10 Oct 2019 20:34:10 +0000 (22:34 +0200)
libstorycode/gtk/gtkslideview.c
libstorycode/slide_priv.h
libstorycode/slide_render_cairo.c

index 2697d5f..11cf05a 100644 (file)
@@ -1104,27 +1104,31 @@ static void gtksv_do_backspace(GtkSlideView *e, signed int dir)
 }
 
 
-static void gtksv_insert_text_in_paragraph(SlideItem *item, int para,
+static void gtksv_insert_text_in_paragraph(SlideItem *item, int para_num,
                                            size_t offs, char *t)
 {
-       /* FIXME! */
-#if 0
-       char *n = malloc(strlen(t) + strlen(item->paras[para].text) + 1);
+       struct slide_text_paragraph *para;
+       int run;
+       size_t run_offs;
+       char *n;
+
+       para = &item->paras[para_num];
+       run = slide_which_run(para, offs, &run_offs);
+
+       n = malloc(strlen(t) + strlen(para->runs[run].text) + 1);
        if ( n == NULL ) return;
-       strncpy(n, item->paras[para].text, offs);
-       n[offs] = '\0';
+
+       strncpy(n, para->runs[run].text, run_offs);
+       n[run_offs] = '\0';
        strcat(n, t);
-       strcat(n, item->paras[para].text+offs);
-       free(item->paras[para].text);
-       item->paras[para].text = n;
-#endif
+       strcat(n, para->runs[run].text+run_offs);
+       free(para->runs[run].text);
+       para->runs[run].text = n;
 }
 
 
 static void gtksv_insert_text(char *t, GtkSlideView *e)
 {
-       /* FIXME! */
-#if 0
        size_t off;
 
        if ( e->cursor_frame == NULL ) return;
@@ -1135,27 +1139,20 @@ static void gtksv_insert_text(char *t, GtkSlideView *e)
        }
        gtksv_unset_selection(e);
 
+       off = slide_pos_trail_to_offset(e->cursor_frame, e->cpos.para,
+                                       e->cpos.pos, e->cpos.trail);
        if ( strcmp(t, "\n") == 0 ) {
-               off = pos_trail_to_offset(e->cursor_frame, e->cpos.para,
-                                         e->cpos.pos, e->cpos.trail);
                slide_item_split_text_paragraph(e->cursor_frame, e->cpos.para, off);
                e->cpos.para++;
                e->cpos.pos = 0;
                e->cpos.trail = 0;
-               gtksv_emit_change_sig(e);
-               gtksv_redraw(e);
-               return;
+       } else {
+               gtksv_insert_text_in_paragraph(e->cursor_frame, e->cpos.para, off, t);
+               e->cpos.pos += strlen(t);
        }
 
-       off = pos_trail_to_offset(e->cursor_frame, e->cpos.para,
-                                 e->cpos.pos, e->cpos.trail);
-       gtksv_insert_text_in_paragraph(e->cursor_frame, e->cpos.para, off, t);
-       pango_layout_set_text(e->cursor_frame->paras[e->cpos.para].layout,
-                             e->cursor_frame->paras[e->cpos.para].text, -1);
-       gtksv_cursor_moveh(e, &e->cpos, +1);
        gtksv_emit_change_sig(e);
        gtksv_redraw(e);
-#endif
 }
 
 
index 64e6d75..d415d33 100644 (file)
@@ -76,4 +76,7 @@ struct _slide
        SlideItem *items;
 };
 
+extern int slide_which_run(struct slide_text_paragraph *para, size_t item_offs,
+                           size_t *run_offs);
+
 #endif /* SLIDE_PRIV_H */
index 32bd236..a1da5da 100644 (file)
@@ -55,8 +55,8 @@ static int slide_positions_equal(struct slide_pos a, struct slide_pos b)
 }
 
 
-static int slide_which_run(struct slide_text_paragraph *para, size_t item_offs,
-                           size_t *run_offs)
+int slide_which_run(struct slide_text_paragraph *para, size_t item_offs,
+                    size_t *run_offs)
 {
        int run;
        size_t pos = 0;