aboutsummaryrefslogtreecommitdiff
path: root/src/sc_interp.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-10-17 21:03:39 +0200
committerThomas White <taw@physics.org>2017-10-17 21:03:39 +0200
commit9c929b373d0ffa3fbd8e0de670caaab95b58a101 (patch)
treebe1637d5c46b63473cca591951b16b1099413f1e /src/sc_interp.c
parent54adeb60b85641f6c1d968200eeb5e5d705c51ea (diff)
Track newlines at end of paragraphs
Diffstat (limited to 'src/sc_interp.c')
-rw-r--r--src/sc_interp.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/sc_interp.c b/src/sc_interp.c
index df00d5e..df559e1 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -887,6 +887,13 @@ static int in_macro(SCInterpreter *scin)
}
+static void set_newline_at_end_last_para(struct frame *fr)
+{
+ if ( fr->paras == NULL ) return;
+ set_newline_at_end(fr->paras[fr->n_paras-1]);
+}
+
+
/* Add the SCBlock to the text in 'frame', at the end */
static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
PangoLanguage *lang, int editable, SCInterpreter *scin)
@@ -895,7 +902,6 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
size_t start, len_bytes;
PangoFontDescription *fontdesc;
double *col;
- int just_closed = 0;
struct sc_state *st = &scin->state[scin->j];
SCBlock *mrb;
@@ -921,20 +927,23 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
}
if ( text[start] == '\n' ) {
- if ( just_closed ) {
+ if ( !last_para_available_for_text(fr) ) {
+ /* Add an empty paragraph */
Paragraph *para = last_open_para(fr);
add_run(para, bl, mrb, start, 0, fontdesc, col);
set_para_spacing(para, st->paraspace);
+ set_newline_at_end(para);
}
+ /* Close this paragraph */
+ set_newline_at_end_last_para(fr);
close_last_paragraph(fr);
start += 1;
- just_closed = 1;
} else {
+ /* Just add some text */
Paragraph *para = last_open_para(fr);
add_run(para, bl, mrb, start, len, fontdesc, col);
set_para_spacing(para, st->paraspace);
start += len;
- just_closed = 0;
}
} while ( start < len_bytes );