diff options
| -rw-r--r-- | text-motions.c | 18 | ||||
| -rw-r--r-- | text-motions.h | 3 | ||||
| -rw-r--r-- | vis.c | 4 |
3 files changed, 25 insertions, 0 deletions
diff --git a/text-motions.c b/text-motions.c index 59b92e0..9089371 100644 --- a/text-motions.c +++ b/text-motions.c @@ -165,6 +165,24 @@ size_t text_line_offset(Text *txt, size_t pos, size_t off) { return it.pos; } +size_t text_line_char_next(Text *txt, size_t pos) { + char c; + Iterator it = text_iterator_get(txt, pos); + if (!text_iterator_byte_get(&it, &c) || c == '\r' || c == '\n') + return pos; + if (!text_iterator_char_next(&it, &c) || c == '\r' || c == '\n') + return pos; + return it.pos; +} + +size_t text_line_char_prev(Text *txt, size_t pos) { + char c; + Iterator it = text_iterator_get(txt, pos); + if (!text_iterator_char_prev(&it, &c) || c == '\n') + return pos; + return it.pos; +} + 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 64f68bf..0f99076 100644 --- a/text-motions.h +++ b/text-motions.h @@ -35,6 +35,9 @@ size_t text_line_lastchar(Text*, size_t pos); size_t text_line_end(Text*, size_t pos); size_t text_line_next(Text*, size_t pos); 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); /* * 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. @@ -105,6 +105,8 @@ enum { MOVE_COLUMN, MOVE_CHAR_PREV, MOVE_CHAR_NEXT, + MOVE_LINE_CHAR_PREV, + MOVE_LINE_CHAR_NEXT, MOVE_WORD_START_NEXT, MOVE_WORD_END_PREV, MOVE_WORD_END_NEXT, @@ -186,6 +188,8 @@ static Movement moves[] = { [MOVE_COLUMN] = { .txt = column, .type = CHARWISE|IDEMPOTENT}, [MOVE_CHAR_PREV] = { .txt = text_char_prev }, [MOVE_CHAR_NEXT] = { .txt = text_char_next }, + [MOVE_LINE_CHAR_PREV] = { .txt = text_line_char_prev, .type = CHARWISE }, + [MOVE_LINE_CHAR_NEXT] = { .txt = text_line_char_next, .type = CHARWISE }, [MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE }, [MOVE_WORD_START_NEXT] = { .txt = text_word_start_next, .type = CHARWISE }, [MOVE_WORD_END_PREV] = { .txt = text_word_end_prev, .type = CHARWISE|INCLUSIVE }, |
