From a8112c90cf0fdf44ceee5b54fed77468f5c15757 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 11 Oct 2015 23:02:38 +0200 Subject: Keep track of the boxes at the three levels: orig, para, wrapped --- src/sc_editor.c | 7 +++++++ src/shape.c | 1 + src/wrap.c | 6 +++++- src/wrap.h | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sc_editor.c b/src/sc_editor.c index 1b1bb04..b9a0032 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -579,6 +579,13 @@ static void insert_text(char *t, SCEditor *e) printf("sps=%i, offs_char=%i\n", sps, sbox->offs_char); sc_insert_text(sbox->scblock, sps+sbox->offs_char, t); + /* Update the length of the box in the unwrapped and un-paragraph-split + * string of wrap boxes */ + sbox->cf->cf->len_chars += 1; + + /* ... and also in the paragraph split but unwrapped box */ + sbox->cf->len_chars += 1; + fr->empty = 0; full_rerender(e); /* FIXME: No need for full */ diff --git a/src/shape.c b/src/shape.c index f483510..24848e5 100644 --- a/src/shape.c +++ b/src/shape.c @@ -94,6 +94,7 @@ static void add_wrap_box(gpointer vi, gpointer vb) box->editable = bas->editable; box->ascent = sc_interp_get_ascent(bas->scin); box->height = sc_interp_get_height(bas->scin); + box->cf = NULL; /* Link to the actual text */ tp = sc_block_contents(bas->bl); diff --git a/src/wrap.c b/src/wrap.c index 63ca84f..3e2e62e 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -756,7 +756,10 @@ static void first_fit(struct wrap_line *boxes, double line_length, line = new_line(fr); len = boxes->boxes[j].width; } - line->boxes[line->n_boxes++] = boxes->boxes[j++]; + line->boxes[line->n_boxes] = boxes->boxes[j]; + line->boxes[line->n_boxes].cf = &boxes->boxes[j]; + line->n_boxes++; + j++; if ( (j > 0) && (boxes->boxes[j-1].type != WRAP_BOX_SENTINEL) ) { @@ -827,6 +830,7 @@ static struct wrap_line *split_paragraph(struct wrap_line *boxes, int *n, alloc_boxes(para); for ( i=start; iboxes[i-start] = boxes->boxes[i]; + para->boxes[i-start].cf = &boxes->boxes[i]; } return para; } diff --git a/src/wrap.h b/src/wrap.h index b15ea3f..ca30e05 100644 --- a/src/wrap.h +++ b/src/wrap.h @@ -65,6 +65,7 @@ struct wrap_box SCBlock *scblock; int offs_char; /* offset (in characters, not bytes) into scblock */ + struct wrap_box *cf; /* Copied from */ /* Pango units */ int width; -- cgit v1.2.3