From 847178be96f11d555d4ef05641382b5a97367f88 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 18 Mar 2018 15:04:06 +0100 Subject: Create a run when placing cursor in an empty paragraph --- src/frame.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/frame.c') 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; -- cgit v1.2.3