diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-04-21 08:06:55 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-04-21 11:05:45 +0200 |
| commit | aca46a0da8969f15d9356c149687f961b6852516 (patch) | |
| tree | ffc96967c3110d9a684fec302973845e7de2b23d /vis.c | |
| parent | 1b1590ed4f33f3da16ff648c7e0f1a45db6811dd (diff) | |
| download | vis-aca46a0da8969f15d9356c149687f961b6852516.tar.gz vis-aca46a0da8969f15d9356c149687f961b6852516.tar.xz | |
Clean up to/till movements
Diffstat (limited to 'vis.c')
| -rw-r--r-- | vis.c | 34 |
1 files changed, 27 insertions, 7 deletions
@@ -649,21 +649,41 @@ static size_t mark_line_goto(const Arg *arg) { } static size_t to(const Arg *arg) { - return text_find_char_next(vis->win->text->data, window_cursor_get(vis->win->win) + 1, - vis->action.key.str, strlen(vis->action.key.str)); + char c; + Text *txt = vis->win->text->data; + size_t pos = window_cursor_get(vis->win->win); + size_t hit = text_find_next(txt, pos+1, vis->search_char); + if (!text_byte_get(txt, hit, &c) || c != vis->search_char[0]) + return pos; + return hit; } static size_t till(const Arg *arg) { - return text_char_prev(vis->win->text->data, to(arg)); + size_t pos = window_cursor_get(vis->win->win); + size_t hit = to(arg); + if (hit != pos) + return text_char_prev(vis->win->text->data, hit); + return pos; } static size_t to_left(const Arg *arg) { - return text_find_char_prev(vis->win->text->data, window_cursor_get(vis->win->win) - 1, - vis->action.key.str, strlen(vis->action.key.str)); + char c; + Text *txt = vis->win->text->data; + size_t pos = window_cursor_get(vis->win->win); + if (pos == 0) + return pos; + size_t hit = text_find_prev(txt, pos-1, vis->search_char); + if (!text_byte_get(txt, hit, &c) || c != vis->search_char[0]) + return pos; + return hit; } static size_t till_left(const Arg *arg) { - return text_char_next(vis->win->text->data, to_left(arg)); + size_t pos = window_cursor_get(vis->win->win); + size_t hit = to_left(arg); + if (hit != pos) + return text_char_next(vis->win->text->data, hit); + return pos; } static size_t line(const Arg *arg) { @@ -822,7 +842,7 @@ static void movement_key(const Arg *arg) { action_reset(&vis->action); return; } - vis->action.key = k; + strncpy(vis->search_char, k.str, sizeof(vis->search_char)); vis->action.movement = &moves[arg->i]; action_do(&vis->action); } |
