diff options
author | Thomas White <taw@physics.org> | 2018-03-04 22:06:28 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-03-04 22:06:28 +0100 |
commit | 6634bdb38e40772cdb263deb94efe170f90cd0dc (patch) | |
tree | b8b3dd7940e1bed962f0ff779e60f2e094ec7ee1 /src | |
parent | f0dded75cadca320160344f20ebd1be3dc72a4c8 (diff) |
Text insertion fix
Diffstat (limited to 'src')
-rw-r--r-- | src/frame.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/frame.c b/src/frame.c index 297b411..13a7909 100644 --- a/src/frame.c +++ b/src/frame.c @@ -408,7 +408,7 @@ void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock, if ( !para->open ) { fprintf(stderr, "Adding a run to a closed paragraph!\n"); - return; + //return; } runs_new = realloc(para->runs, @@ -1029,29 +1029,40 @@ void insert_text_in_paragraph(Paragraph *para, size_t offs, const char *t) } run = ¶->runs[nrun]; - if ( (sc_block_name(run->scblock) != NULL) - && (strcmp(sc_block_name(run->scblock), "newpara") == 0) ) + /* Translate paragraph offset for insertion into SCBlock offset */ + run_offs = offs - get_paragraph_offset(para, nrun); + + if ( (sc_block_name(run->rscblock) != NULL) + && (strcmp(sc_block_name(run->rscblock), "newpara") == 0) ) { - SCBlock *nnp; - printf("Inserting into newpara block...\n"); + if ( para->n_runs == 1 ) { - /* Add a new \newpara block after this one */ - nnp = sc_block_append(run->scblock, "newpara", - NULL, NULL, NULL); + SCBlock *nnp; + printf("Inserting into newpara block...\n"); - /* The first \newpara block becomes a normal anonymous block */ - sc_block_set_name(run->scblock, NULL); + /* The first \newpara block becomes a normal anonymous block */ + sc_block_set_name(run->rscblock, NULL); + sc_block_set_contents(run->rscblock, strdup(t)); + + /* Add a new \newpara block after this one */ + nnp = sc_block_append(run->rscblock, "newpara", + NULL, NULL, NULL); + add_run(para, nnp, nnp, 0, run->fontdesc, run->col); - if ( para->newline_at_end == run->scblock ) { para->newline_at_end = nnp; - printf("Replaced the newpara block\n"); + + return; + + } else { + + run = ¶->runs[nrun-1]; + run_offs = strlen(sc_block_contents(run->rscblock)); + } } - /* Translate paragraph offset for insertion into SCBlock offset */ - run_offs = offs - get_paragraph_offset(para, nrun); sc_insert_text(run->rscblock, run_offs, t); } |