diff options
author | Thomas White <taw@bitwiz.org.uk> | 2015-10-13 23:25:00 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2015-10-13 23:25:00 +0200 |
commit | e6e84a27ee6eb6c52fc26aa4f175e85af07fd901 (patch) | |
tree | 101c94669b9abb86113777a70497f0de6000b0a0 /src/sc_editor.c | |
parent | b825140f394a00b0935492e619e0d7b094607233 (diff) |
Make text insertion (mostly) work
Diffstat (limited to 'src/sc_editor.c')
-rw-r--r-- | src/sc_editor.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/sc_editor.c b/src/sc_editor.c index c8ef09a..6619b06 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -568,7 +568,9 @@ static void update_local(SCEditor *e, struct frame *fr, int line, int bn) cairo_t *cr; /* Shape the box again */ - shape_box(box); + shape_box(box->cf->cf); + box->glyphs = box->cf->cf->glyphs; + box->cf->glyphs = box->cf->cf->glyphs; /* Wrap the paragraph again */ wrap_contents(fr); /* FIXME: Only the current paragraph */ @@ -585,6 +587,26 @@ static void update_local(SCEditor *e, struct frame *fr, int line, int bn) } +static void shift_box_offsets(struct frame *fr, struct wrap_box *box, int n) +{ + int i; + int sn = 0; + + for ( i=0; i<fr->boxes->n_boxes; i++ ) { + if ( &fr->boxes->boxes[i] == box ) { + sn = i+1; + break; + } + } + + assert(sn > 0); /* Lowest it can possibly be is 1 */ + + for ( i=sn; i<fr->boxes->n_boxes; i++ ) { + fr->boxes->boxes[i].offs_char += n; + } +} + + static void insert_text(char *t, SCEditor *e) { int sln, sbx, sps; @@ -612,11 +634,13 @@ static void insert_text(char *t, SCEditor *e) /* ... and also in the paragraph split but unwrapped box */ sbox->cf->len_chars += 1; + /* Tweak the offsets of all the subsequent boxes */ + shift_box_offsets(fr, sbox->cf->cf, 1); + fr->empty = 0; update_local(e, fr, sln, sbx); - /* ... by doing this properly */ fixup_cursor(e); advance_cursor(e); |