aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-07-27 21:04:20 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-07-28 13:21:50 +0200
commit620518966fb99511c506af292cc1885f7a419881 (patch)
treea3ae882163f2837bd4b55a5a67dc46b0c6fbf731
parentc9499ddd97d1bb8395e896050e92c6eee7e4b205 (diff)
downloadvis-620518966fb99511c506af292cc1885f7a419881.tar.gz
vis-620518966fb99511c506af292cc1885f7a419881.tar.xz
vis: add per cursor registers
-rw-r--r--view.c6
-rw-r--r--view.h3
-rw-r--r--vis.c10
3 files changed, 17 insertions, 2 deletions
diff --git a/view.c b/view.c
index 875635f..43915ce 100644
--- a/view.c
+++ b/view.c
@@ -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) {
diff --git a/view.h b/view.h
index ce2dc93..97fd12c 100644
--- a/view.h
+++ b/view.h
@@ -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*);
diff --git a/vis.c b/vis.c
index 9ca92cd..d11c696 100644
--- a/vis.c
+++ b/vis.c
@@ -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,
};