aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-13 17:05:56 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-13 17:05:56 +0200
commit0ab78db2cf8ca04c9b882f7b572819c8f34323ae (patch)
tree6aca810fc57575349951738bcaa6446e37b9486c
parent592dc705e07083b1e9763042101a3a3c65c2e609 (diff)
downloadvis-0ab78db2cf8ca04c9b882f7b572819c8f34323ae.tar.gz
vis-0ab78db2cf8ca04c9b882f7b572819c8f34323ae.tar.xz
view: add view_cursors_new_force function
To create a cursor even if there already exists one at the same position. Should only be used if all but one of the cursors will later be removed.
-rw-r--r--view.c14
-rw-r--r--view.h7
2 files changed, 17 insertions, 4 deletions
diff --git a/view.c b/view.c
index ee6d5fb..f2a0c90 100644
--- a/view.c
+++ b/view.c
@@ -1059,7 +1059,7 @@ size_t view_screenline_goto(View *view, int n) {
return pos;
}
-Cursor *view_cursors_new(View *view, size_t pos) {
+static Cursor *cursors_new(View *view, size_t pos, bool force) {
Cursor *c = calloc(1, sizeof(*c));
if (!c)
return NULL;
@@ -1074,7 +1074,7 @@ Cursor *view_cursors_new(View *view, size_t pos) {
Cursor *prev = NULL, *next = NULL;
size_t cur = view_cursors_pos(view->cursor);
- if (pos > cur) {
+ if (pos >= cur) {
prev = view->cursor;
for (next = prev->next; next; prev = next, next = next->next) {
cur = view_cursors_pos(next);
@@ -1090,7 +1090,7 @@ Cursor *view_cursors_new(View *view, size_t pos) {
}
}
- if (pos == cur)
+ if (pos == cur && !force)
goto err;
for (Cursor *after = next; after; after = after->next)
@@ -1115,6 +1115,14 @@ err:
return NULL;
}
+Cursor *view_cursors_new(View *view, size_t pos) {
+ return cursors_new(view, pos, false);
+}
+
+Cursor *view_cursors_new_force(View *view, size_t pos) {
+ return cursors_new(view, pos, true);
+}
+
int view_cursors_count(View *view) {
return view->cursor_count;
}
diff --git a/view.h b/view.h
index fd0c329..fadaaba 100644
--- a/view.h
+++ b/view.h
@@ -119,8 +119,13 @@ 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, at given position */
+/* create a new cursor at given position, fails if there already
+ * exists a cursor at the same position */
Cursor *view_cursors_new(View*, size_t pos);
+/* create a new cursor even if there already is one located at the
+ * same position, this should only be used if the one of the two
+ * cursors will later be disposed */
+Cursor *view_cursors_new_force(View*, size_t pos);
/* get number of active cursors */
int view_cursors_count(View*);
/* get index/relative order at time of creation of a cursor [0,count-1] */