aboutsummaryrefslogtreecommitdiff
path: root/src/frame.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-03-18 15:04:06 +0100
committerThomas White <taw@physics.org>2018-03-18 23:14:13 +0100
commit847178be96f11d555d4ef05641382b5a97367f88 (patch)
treea7878b36d81a7283d1ad1e27c6a47fbe0bebf444 /src/frame.c
parent546bfb401b943b0b5e91f3674c450c4a78aeb6aa (diff)
Create a run when placing cursor in an empty paragraph
Diffstat (limited to 'src/frame.c')
-rw-r--r--src/frame.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/frame.c b/src/frame.c
index a125ce6..62fe72c 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -699,6 +699,44 @@ void sort_positions(struct edit_pos *a, struct edit_pos *b)
}
+void ensure_run(struct frame *fr, struct edit_pos cpos)
+{
+ SCBlock *bl;
+ Paragraph *para = fr->paras[cpos.para];
+ if ( para->n_runs > 0 ) return;
+
+ if ( para->type != PARA_TYPE_TEXT ) return;
+
+ if ( para->scblock != para->rscblock ) {
+ fprintf(stderr, "Need to add run, but paragraph not editable\n");
+ return;
+ }
+
+ if ( para->scblock != NULL ) {
+
+ bl = sc_block_prepend(para->scblock, fr->scblocks);
+ if ( bl == NULL ) {
+ fprintf(stderr, "Couldn't prepend block\n");
+ return;
+ }
+ sc_block_set_contents(bl, strdup(""));
+
+ } else {
+
+ /* If the paragraph's SCBlock is NULL, it means this paragraph
+ * is right at the end of the document. The last thing in the
+ * document is something like \newpara. */
+ bl = sc_block_append_end(fr->scblocks, NULL, NULL, strdup(""));
+
+ }
+
+ para->scblock = bl;
+ para->rscblock = bl;
+ add_run(para, bl, bl, fr->fontdesc, fr->col);
+ wrap_paragraph(para, NULL, fr->w - fr->pad_l - fr->pad_r, 0, 0);
+}
+
+
int find_cursor(struct frame *fr, double x, double y, struct edit_pos *pos)
{
double pad = fr->pad_t;