diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-04-07 12:52:10 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-04-08 22:54:36 +0200 |
| commit | 3349b97344c6c7032bff7aaa13985406ca571c34 (patch) | |
| tree | 5ebce693c3f06ba8a786f52ebdc1e8b4e1f7c395 | |
| parent | df762bf0bbdf373a53fdfd5f90b730fe6f7850bb (diff) | |
| download | vis-3349b97344c6c7032bff7aaa13985406ca571c34.tar.gz vis-3349b97344c6c7032bff7aaa13985406ca571c34.tar.xz | |
text: adjust iterator position when switching to adjacent pieces
| -rw-r--r-- | text.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1391,12 +1391,14 @@ bool text_iterator_char_get(Iterator *it, char *c) { } bool text_iterator_next(Iterator *it) { - return text_iterator_init(it, it->pos, it->piece ? it->piece->next : NULL, 0); + size_t rem = it->end - it->text; + return text_iterator_init(it, it->pos+rem, it->piece ? it->piece->next : NULL, 0); } bool text_iterator_prev(Iterator *it) { + size_t off = it->text - it->start; size_t len = it->piece && it->piece->prev ? it->piece->prev->len : 0; - return text_iterator_init(it, it->pos, it->piece ? it->piece->prev : NULL, len); + return text_iterator_init(it, it->pos-off, it->piece ? it->piece->prev : NULL, len); } bool text_iterator_valid(const Iterator *it) { |
