aboutsummaryrefslogtreecommitdiff
path: root/text-motions.c
diff options
context:
space:
mode:
Diffstat (limited to 'text-motions.c')
-rw-r--r--text-motions.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/text-motions.c b/text-motions.c
index 97012bd..aa779b2 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -46,7 +46,7 @@ size_t text_char_prev(Text *txt, size_t pos) {
return it.pos;
}
-size_t text_find_next(Text *txt, size_t pos, const char *s) {
+static size_t find_next(Text *txt, size_t pos, const char *s, bool line) {
if (!s)
return pos;
size_t len = strlen(s), matched = 0;
@@ -61,11 +61,21 @@ size_t text_find_next(Text *txt, size_t pos, const char *s) {
matched = 0;
}
text_iterator_byte_next(&it, NULL);
+ if (line && c == '\n')
+ break;
}
return matched == len ? it.pos - len : pos;
}
-size_t text_find_prev(Text *txt, size_t pos, const char *s) {
+size_t text_find_next(Text *txt, size_t pos, const char *s) {
+ return find_next(txt, pos, s, false);
+}
+
+size_t text_line_find_next(Text *txt, size_t pos, const char *s) {
+ return find_next(txt, pos, s, true);
+}
+
+static size_t find_prev(Text *txt, size_t pos, const char *s, bool line) {
if (!s)
return pos;
size_t len = strlen(s), matched = len - 1;
@@ -84,10 +94,20 @@ size_t text_find_prev(Text *txt, size_t pos, const char *s) {
matched = len - 1;
}
text_iterator_byte_prev(&it, NULL);
+ if (line && c == '\n')
+ break;
}
return matched == 0 ? it.pos : pos;
}
+size_t text_find_prev(Text *txt, size_t pos, const char *s) {
+ return find_prev(txt, pos, s, false);
+}
+
+size_t text_line_find_prev(Text *txt, size_t pos, const char *s) {
+ return find_prev(txt, pos, s, true);
+}
+
size_t text_line_prev(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, pos);