aboutsummaryrefslogtreecommitdiff
path: root/text-motions.c
diff options
context:
space:
mode:
Diffstat (limited to 'text-motions.c')
-rw-r--r--text-motions.c14
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);