diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-10 21:00:47 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-10 21:00:47 +0200 |
| commit | 8d960c6dc536efcbe5dc2fae330a95015e0aae86 (patch) | |
| tree | 5cd3ade394c11968c47ab4de000459c32feaf439 /text-motions.c | |
| parent | 16bd3ede6241a4790246ad7fcbde21e8c1d626a0 (diff) | |
| download | vis-8d960c6dc536efcbe5dc2fae330a95015e0aae86.tar.gz vis-8d960c6dc536efcbe5dc2fae330a95015e0aae86.tar.xz | |
text-motions: add text_line_prev function
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/text-motions.c b/text-motions.c index 25ff87c..15fdd2d 100644 --- a/text-motions.c +++ b/text-motions.c @@ -73,6 +73,20 @@ size_t text_find_char_prev(Text *txt, size_t pos, const char *s, size_t len) { return matched == 0 ? it.pos : pos; } +size_t text_line_prev(Text *txt, size_t pos) { + char c; + Iterator it = text_iterator_get(txt, pos); + if (!text_iterator_byte_get(&it, &c)) + return pos; + if (c == '\r') + text_iterator_byte_prev(&it, &c); + if (c == '\n') + text_iterator_byte_prev(&it, &c); + while (text_iterator_byte_get(&it, &c) && c != '\n') + text_iterator_byte_prev(&it, NULL); + return it.pos; +} + size_t text_line_begin(Text *txt, size_t pos) { char c; Iterator it = text_iterator_get(txt, pos); |
