diff options
| -rw-r--r-- | main.c | 22 | ||||
| -rw-r--r-- | view.c | 7 | ||||
| -rw-r--r-- | view.h | 4 | ||||
| -rw-r--r-- | vis-operators.c | 15 |
4 files changed, 23 insertions, 25 deletions
@@ -1190,15 +1190,15 @@ static const char *repeat(Vis *vis, const char *keys, const Arg *arg) { static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - size_t pos = view_cursor_get(view); - Cursor *cursor = view_cursors_new(view); - if (cursor) { - view_cursors_to(cursor, pos); - if (arg->i > 0) - view_line_down(cursor); - else if (arg->i < 0) - view_line_up(cursor); - } + Cursor *cursor = view_cursors_primary_get(view); + size_t oldpos = view_cursors_pos(cursor); + if (arg->i > 0) + view_line_down(cursor); + else if (arg->i < 0) + view_line_up(cursor); + size_t newpos = view_cursors_pos(cursor); + view_cursors_to(cursor, oldpos); + view_cursors_new(view, newpos); return keys; } @@ -1294,11 +1294,11 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar free(buf); if (text_range_valid(&word)) { - cursor = view_cursors_new(view); + size_t pos = text_char_prev(txt, word.end); + cursor = view_cursors_new(view, pos); if (!cursor) return keys; view_cursors_selection_set(cursor, &word); - view_cursors_to(cursor, text_char_prev(txt, word.end)); } return keys; } @@ -737,7 +737,7 @@ View *view_new(Text *text, lua_State *lua) { View *view = calloc(1, sizeof(View)); if (!view) return NULL; - if (!view_cursors_new(view)) { + if (!view_cursors_new(view, EPOS)) { view_free(view); return NULL; } @@ -1051,17 +1051,18 @@ size_t view_screenline_goto(View *view, int n) { return pos; } -Cursor *view_cursors_new(View *view) { +Cursor *view_cursors_new(View *view, size_t pos) { Cursor *c = calloc(1, sizeof(*c)); if (!c) return NULL; - c->view = view; c->next = view->cursors; if (view->cursors) view->cursors->prev = c; view->cursors = c; view->cursor = c; + if (pos != EPOS) + view_cursors_to(c, pos); return c; } @@ -119,8 +119,8 @@ void view_scroll_to(View*, size_t pos); * position is visible. if the position is in the middle of a line, try to * adjust the viewport in such a way that the whole line is displayed */ void view_cursor_to(View*, size_t pos); -/* create a new cursor */ -Cursor *view_cursors_new(View*); +/* create a new cursor, at given position */ +Cursor *view_cursors_new(View*, size_t pos); /* get number of active cursors */ int view_cursors_count(View*); /* exist there more than 1 cursor */ diff --git a/vis-operators.c b/vis-operators.c index f9e2ec9..0be30ad 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -169,15 +169,12 @@ static size_t op_cursor(Vis *vis, Text *txt, OperatorContext *c) { View *view = vis->win->view; Filerange r = text_range_linewise(txt, &c->range); for (size_t line = text_range_line_first(txt, &r); line != EPOS; line = text_range_line_next(txt, &r, line)) { - Cursor *cursor = view_cursors_new(view); - if (cursor) { - size_t pos; - if (c->arg->i == VIS_OP_CURSOR_EOL) - pos = text_line_finish(txt, line); - else - pos = text_line_start(txt, line); - view_cursors_to(cursor, pos); - } + size_t pos; + if (c->arg->i == VIS_OP_CURSOR_EOL) + pos = text_line_finish(txt, line); + else + pos = text_line_start(txt, line); + view_cursors_new(view, pos); } return EPOS; } |
