From c9499ddd97d1bb8395e896050e92c6eee7e4b205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 27 Jul 2015 20:44:49 +0200 Subject: vis: add an operator to create new cursors The operator creates a new cursor at the start of every line covered by the given range. It is currently only available as CTRL+O in visual mode. --- vis.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 216ee2f..9ca92cd 100644 --- a/vis.c +++ b/vis.c @@ -56,6 +56,7 @@ static size_t op_case_change(OperatorContext *c); static size_t op_join(OperatorContext *c); static size_t op_repeat_insert(OperatorContext *c); static size_t op_repeat_replace(OperatorContext *c); +static size_t op_cursor(OperatorContext *c); /* these can be passed as int argument to operator(&(const Arg){ .i = OP_*}) */ enum { @@ -69,6 +70,7 @@ enum { OP_JOIN, OP_REPEAT_INSERT, OP_REPEAT_REPLACE, + OP_CURSOR, }; static Operator ops[] = { @@ -82,6 +84,7 @@ static Operator ops[] = { [OP_JOIN] = { op_join }, [OP_REPEAT_INSERT] = { op_repeat_insert }, [OP_REPEAT_REPLACE] = { op_repeat_replace }, + [OP_CURSOR] = { op_cursor }, }; #define PAGE INT_MAX @@ -568,6 +571,18 @@ static size_t op_case_change(OperatorContext *c) { return c->pos; } +static size_t op_cursor(OperatorContext *c) { + Text *txt = vis->win->file->text; + 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) + view_cursors_to(cursor, text_line_start(txt, line)); + } + return EPOS; +} + static size_t op_join(OperatorContext *c) { Text *txt = vis->win->file->text; size_t pos = text_line_begin(txt, c->range.end), prev_pos; -- cgit v1.2.3