diff options
| -rw-r--r-- | view.c | 6 | ||||
| -rw-r--r-- | view.h | 3 | ||||
| -rw-r--r-- | vis.c | 10 |
3 files changed, 17 insertions, 2 deletions
@@ -41,6 +41,7 @@ struct Cursor { /* cursor position */ Line *line; /* screen line on which cursor currently resides */ Mark mark; /* mark used to keep track of current cursor position */ Selection *sel; /* selection (if any) which folows the cursor upon movement */ + Register reg; /* per cursor register to support yank/put operation */ View *view; /* associated view to which this cursor belongs */ Cursor *prev, *next;/* previous/next cursors in no particular order */ }; @@ -892,6 +893,7 @@ Cursor *view_cursors_new(View *view) { void view_cursors_free(Cursor *c) { if (!c) return; + register_release(&c->reg); if (c->prev) c->prev->next = c->next; if (c->next) @@ -923,6 +925,10 @@ size_t view_cursors_pos(Cursor *c) { return text_mark_get(c->view->text, c->mark); } +Register *view_cursors_register(Cursor *c) { + return &c->reg; +} + void view_cursors_scroll_to(Cursor *c, size_t pos) { View *view = c->view; if (view->cursor == c) { @@ -3,6 +3,7 @@ #include <stddef.h> #include <stdbool.h> +#include "register.h" #include "text.h" #include "ui.h" #include "syntax.h" @@ -130,6 +131,8 @@ size_t view_cursors_pos(Cursor*); /* place cursor at `pos' which should be in the interval [0, text-size] */ void view_cursors_to(Cursor*, size_t pos); void view_cursors_scroll_to(Cursor*, size_t pos); +/* get register associated with this register */ +Register *view_cursors_register(Cursor*); /* start selected area at current cursor position. further cursor movements * will affect the selected region. */ void view_cursors_selection_start(Cursor*); @@ -1227,16 +1227,22 @@ static void action_do(Action *a) { Text *txt = vis->win->file->text; View *view = vis->win->view; int count = MAX(1, a->count); + Cursor *cursor = view_cursors(view), *next; + bool multiple_cursors = cursor && view_cursors_next(cursor); - for (Cursor *cursor = view_cursors(view), *next; cursor; cursor = next) { + for (; cursor; cursor = next) { next = view_cursors_next(cursor); size_t pos = view_cursors_pos(cursor); + Register *reg = a->reg ? a->reg : &vis->registers[REG_DEFAULT]; + if (multiple_cursors) + reg = view_cursors_register(cursor); + OperatorContext c = { .count = a->count, .pos = pos, .range = text_range_empty(), - .reg = a->reg ? a->reg : &vis->registers[REG_DEFAULT], + .reg = reg, .linewise = a->linewise, .arg = &a->arg, }; |
