From 0329e4aee01778f67c718cd827daa6bcfcef45f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 24 Jul 2015 18:43:18 +0200 Subject: text-motion: introduce text_line_{up,down} --- text-motions.c | 12 ++++++++++++ text-motions.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/text-motions.c b/text-motions.c index 9089371..43077e9 100644 --- a/text-motions.c +++ b/text-motions.c @@ -183,6 +183,18 @@ size_t text_line_char_prev(Text *txt, size_t pos) { return it.pos; } +size_t text_line_up(Text *txt, size_t pos) { + size_t bol = text_line_begin(txt, pos); + size_t prev = text_line_prev(txt, bol); + return text_line_offset(txt, prev, pos - bol); +} + +size_t text_line_down(Text *txt, size_t pos) { + size_t bol = text_line_begin(txt, pos); + size_t next = text_line_next(txt, bol); + return text_line_offset(txt, next, pos - bol); +} + static size_t text_customword_start_next(Text *txt, size_t pos, int (*isboundry)(int)) { char c; Iterator it = text_iterator_get(txt, pos); diff --git a/text-motions.h b/text-motions.h index 3c7c9c5..438a42f 100644 --- a/text-motions.h +++ b/text-motions.h @@ -39,6 +39,9 @@ size_t text_line_offset(Text*, size_t pos, size_t off); /* move to the next/previous character on the same line */ size_t text_line_char_next(Text*, size_t pos); size_t text_line_char_prev(Text*, size_t pos); +/* move to same offset in previous/next line */ +size_t text_line_up(Text*, size_t pos); +size_t text_line_down(Text*, size_t pos); /* * A longword consists of a sequence of non-blank characters, separated with * white space. TODO?: An empty line is also considered to be a word. -- cgit v1.2.3