From e7d62e1cd2023fc0b4eedc41aa532c22bb96117c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Jan 2018 22:54:33 +0100 Subject: Try deleting based on macro contents if paragraphs can't be merged straight away Also, avoid a segfault if it still doesn't work after that. --- src/frame.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/frame.c b/src/frame.c index 1bc21bc..656bf5c 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1312,6 +1312,19 @@ void merge_paragraphs(struct frame *fr, int para) return; } + /* Delete the \newpara block to unite the paragraphs */ + n = get_newline_at_end(p1); + assert(n != NULL); + + if ( sc_block_delete(&fr->scblocks, n) ) { + if ( p1->runs[p1->n_runs-1].macro_contents != NULL ) { + if ( sc_block_delete(&p1->runs[p1->n_runs-1].macro_contents, n) ) { + fprintf(stderr, "Failed to delete paragraph end sentinel.\n"); + return; + } + } + } + /* All the runs from p2 get added to p1 */ runs_new = realloc(p1->runs, (p1->n_runs+p2->n_runs)*sizeof(struct text_run)); @@ -1321,11 +1334,6 @@ void merge_paragraphs(struct frame *fr, int para) } p1->runs = runs_new; - /* Delete the \newpara block to unite the paragraphs */ - n = get_newline_at_end(p1); - assert(n != NULL); - sc_block_delete(&fr->scblocks, n); - /* The end of the united paragraph should now be the end of the * second one */ set_newline_at_end(p1, get_newline_at_end(p2)); -- cgit v1.2.3