aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2016-07-07 23:36:17 +0200
committerThomas White <taw@bitwiz.org.uk>2016-07-07 23:36:17 +0200
commit86caa7da9afb4f2dbd3912da7b28e9ebc448aa72 (patch)
tree484209cc4356b5fe21bf575c5d03f4a278514d4b /src
parentf2d8a677bc509b05c1ec07a990e497a20db51695 (diff)
Allow typing into non-text paragraphs
Diffstat (limited to 'src')
-rw-r--r--src/frame.c19
-rw-r--r--src/frame.h10
-rw-r--r--src/sc_editor.c49
3 files changed, 65 insertions, 13 deletions
diff --git a/src/frame.c b/src/frame.c
index 32de26e..d818d6c 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -45,13 +45,6 @@ struct text_run
double col[4];
};
-enum para_type
-{
- PARA_TYPE_TEXT,
- PARA_TYPE_IMAGE,
- PARA_TYPE_CALLBACK
-};
-
struct _paragraph
{
enum para_type type;
@@ -1070,3 +1063,15 @@ void *get_para_bvp(Paragraph *para)
if ( para->type != PARA_TYPE_CALLBACK ) return NULL;
return para->bvp;
}
+
+
+SCBlock *para_scblock(Paragraph *para)
+{
+ return para->scblock;
+}
+
+
+enum para_type para_type(Paragraph *para)
+{
+ return para->type;
+}
diff --git a/src/frame.h b/src/frame.h
index 3f343dc..bf09e52 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -49,6 +49,13 @@ typedef enum
GRAD_VERT
} GradientType;
+enum para_type
+{
+ PARA_TYPE_TEXT,
+ PARA_TYPE_IMAGE,
+ PARA_TYPE_CALLBACK
+};
+
typedef struct _paragraph Paragraph;
struct frame
@@ -166,4 +173,7 @@ extern void *get_para_bvp(Paragraph *para);
extern void merge_paragraphs(struct frame *fr, int para);
+extern enum para_type para_type(Paragraph *para);
+extern SCBlock *para_scblock(Paragraph *para);
+
#endif /* FRAME_H */
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 9c5443d..db0ac87 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -595,12 +595,49 @@ static void insert_text(char *t, SCEditor *e)
}
para = e->cursor_frame->paras[e->cursor_para];
- insert_text_in_paragraph(para, e->cursor_pos+e->cursor_trail, t);
- wrap_paragraph(para, NULL, e->cursor_frame->w - e->cursor_frame->pad_l
- - e->cursor_frame->pad_r);
- cursor_moveh(e->cursor_frame, &e->cursor_para,
- &e->cursor_pos, &e->cursor_trail, +1);
- sc_editor_redraw(e);
+
+ /* Is this paragraph even a text one? */
+ if ( para_type(para) == PARA_TYPE_TEXT ) {
+
+
+ /* Yes. The "easy" case */
+ insert_text_in_paragraph(para, e->cursor_pos+e->cursor_trail,
+ t);
+ wrap_paragraph(para, NULL,
+ e->cursor_frame->w - e->cursor_frame->pad_l
+ - e->cursor_frame->pad_r);
+ cursor_moveh(e->cursor_frame, &e->cursor_para,
+ &e->cursor_pos, &e->cursor_trail, +1);
+
+ sc_editor_redraw(e);
+
+ } else {
+
+ SCBlock *ad;
+ char *tmp;
+
+ tmp = malloc(strlen(t)+2);
+ strcpy(tmp, "\n");
+ strcat(tmp, t);
+
+ /* FIXME: We should not assume that box void pointers correspond
+ * to "real" scblocks for callback paragraphs. Not in this
+ * file, at least. It would be OK in narrative_window.c where
+ * we know there aren't any other callbacks */
+ ad = get_para_bvp(para);
+ if ( ad == NULL ) {
+ ad = para_scblock(para);
+ }
+
+ /* No. Create a new text paragraph straight afterwards */
+ sc_block_insert_after(ad, NULL, NULL, tmp);
+ full_rerender(e);
+
+ /* FIXME: Find the cursor again */
+
+ sc_editor_redraw(e);
+ }
+
}