diff options
author | Thomas White <taw@bitwiz.org.uk> | 2016-09-21 14:33:50 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2016-09-21 14:33:50 +0200 |
commit | 6c5b9480352251c2d221eb7997fdd6dd358d7366 (patch) | |
tree | e380032f80e5696d320b9ea6196dfe08a38946bf /src/frame.c | |
parent | 8ebf692bcd8ef5f949afb01e777e58ee607533c4 (diff) |
Fix abuse of cursor_trail
cursor_pos is a byte offset, but cursor_trail is a number of characters.
Therefore, adding them together is always wrong.
This fixes problems when inserting multi-byte characters.
Diffstat (limited to 'src/frame.c')
-rw-r--r-- | src/frame.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/frame.c b/src/frame.c index 11c6d8f..5c20437 100644 --- a/src/frame.c +++ b/src/frame.c @@ -764,6 +764,25 @@ static int which_run(Paragraph *para, size_t offs) } +size_t pos_trail_to_offset(Paragraph *para, size_t offs, int trail) +{ + glong char_offs; + const char *run_text; + struct text_run *run; + int nrun; + char *ptr; + + nrun = which_run(para, offs); + run= ¶->runs[nrun]; + run_text = sc_block_contents(run->scblock) + run->scblock_offs_bytes; + char_offs = g_utf8_pointer_to_offset(run_text, run_text+offs); + char_offs += trail; + + ptr = g_utf8_offset_to_pointer(run_text, char_offs); + return ptr - run_text; +} + + void insert_text_in_paragraph(Paragraph *para, size_t offs, const char *t) { int nrun; |