diff options
Diffstat (limited to 'src/dged/text.c')
| -rw-r--r-- | src/dged/text.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/dged/text.c b/src/dged/text.c index 0a92933..82c49bc 100644 --- a/src/dged/text.c +++ b/src/dged/text.c @@ -77,9 +77,14 @@ void text_clear(struct text *text) { // given `char_idx` as a character index, return the byte index uint32_t charidx_to_byteidx(struct line *line, uint32_t char_idx) { + if (line->nchars == 0) { + return 0; + } + if (char_idx > line->nchars) { - return line->nbytes; + return line->nbytes - 1; } + return utf8_nbytes(line->data, line->nbytes, char_idx); } |
