aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-03-10 20:53:47 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-03-10 22:36:54 +0100
commit5e632554d9bf7ea48783702ea59585639e1797bf (patch)
tree5691f504dd0c9974d1579469094a9c1fc2b24967
parent5f8760a614e11dc2f665ed4a23309875a6af61df (diff)
downloadvis-5e632554d9bf7ea48783702ea59585639e1797bf.tar.gz
vis-5e632554d9bf7ea48783702ea59585639e1797bf.tar.xz
view: clean up API functions related to primary cursor handling
The currently visible display port is always adjusted in a way that the primary cursor is visible.
-rw-r--r--main.c10
-rw-r--r--view.c14
-rw-r--r--view.h6
-rw-r--r--vis-prompt.c3
4 files changed, 23 insertions, 10 deletions
diff --git a/main.c b/main.c
index f3bbc3f..8a0487b 100644
--- a/main.c
+++ b/main.c
@@ -1242,7 +1242,7 @@ static const char *cursors_clear(Vis *vis, const char *keys, const Arg *arg) {
if (view_cursors_count(view) > 1)
view_cursors_clear(view);
else
- view_cursors_selection_clear(view_cursor(view));
+ view_cursors_selection_clear(view_cursors_primary_get(view));
return keys;
}
@@ -1264,7 +1264,7 @@ static const char *cursors_select(Vis *vis, const char *keys, const Arg *arg) {
static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *arg) {
Text *txt = vis_text(vis);
View *view = vis_view(vis);
- Cursor *cursor = view_cursor(view);
+ Cursor *cursor = view_cursors_primary_get(view);
Filerange sel = view_cursors_selection_get(cursor);
if (!text_range_valid(&sel))
return keys;
@@ -1287,16 +1287,16 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar
static const char *cursors_select_skip(Vis *vis, const char *keys, const Arg *arg) {
View *view = vis_view(vis);
- Cursor *cursor = view_cursor(view);
+ Cursor *cursor = view_cursors_primary_get(view);
keys = cursors_select_next(vis, keys, arg);
- if (cursor != view_cursor(view))
+ if (cursor != view_cursors_primary_get(view))
view_cursors_dispose(cursor);
return keys;
}
static const char *cursors_remove(Vis *vis, const char *keys, const Arg *arg) {
View *view = vis_view(vis);
- view_cursors_dispose(view_cursor(view));
+ view_cursors_dispose(view_cursors_primary_get(view));
view_cursor_to(view, view_cursor_get(view));
return keys;
}
diff --git a/view.c b/view.c
index 877b705..fb3a4a7 100644
--- a/view.c
+++ b/view.c
@@ -1116,10 +1116,20 @@ Cursor *view_cursors(View *view) {
return view->cursors;
}
-Cursor *view_cursor(View *view) {
+Cursor *view_cursors_primary_get(View *view) {
return view->cursor;
}
+void view_cursors_primary_set(Cursor *c) {
+ if (!c)
+ return;
+ View *view = c->view;
+ view->cursor = c;
+ Filerange sel = view_cursors_selection_get(c);
+ view_cursors_to(c, view_cursors_pos(c));
+ view_cursors_selection_set(c, &sel);
+}
+
Cursor *view_cursors_prev(Cursor *c) {
return c->prev;
}
@@ -1158,7 +1168,7 @@ void view_cursors_scroll_to(Cursor *c, size_t pos) {
void view_cursors_to(Cursor *c, size_t pos) {
View *view = c->view;
- if (c->view->cursors == c) {
+ if (c->view->cursor == c) {
c->mark = text_mark_set(view->text, pos);
size_t max = text_size(view->text);
diff --git a/view.h b/view.h
index 7119e56..f33f1a8 100644
--- a/view.h
+++ b/view.h
@@ -128,12 +128,14 @@ void view_cursors_dispose(Cursor*);
/* only keep the main cursor, release all others together with their
* selections (if any) */
void view_cursors_clear(View*);
-/* get the main cursor which is always in the visible viewport */
-Cursor *view_cursor(View*);
/* get the first cursor */
Cursor *view_cursors(View*);
+/* get other cursors, no ordering is guaranteed */
Cursor *view_cursors_prev(Cursor*);
Cursor *view_cursors_next(Cursor*);
+/* get the primary cursor which is always in the visible viewport */
+Cursor *view_cursors_primary_get(View*);
+void view_cursors_primary_set(Cursor*);
/* get current position of cursor in bytes from the start of the file */
size_t view_cursors_pos(Cursor*);
/* get/set zero based index of cell on which cursor currently resides,
diff --git a/vis-prompt.c b/vis-prompt.c
index 42b1a2c..e9f8277 100644
--- a/vis-prompt.c
+++ b/vis-prompt.c
@@ -164,7 +164,8 @@ void vis_prompt_show(Vis *vis, const char *title) {
view_options_set(prompt->view, UI_OPTION_ONELINE);
Text *txt = prompt->file->text;
text_insert(txt, text_size(txt), title, strlen(title));
- view_cursors_scroll_to(view_cursor(prompt->view), text_size(txt));
+ Cursor *cursor = view_cursors_primary_get(prompt->view);
+ view_cursors_scroll_to(cursor, text_size(txt));
view_draw(prompt->view);
prompt->parent = active;
prompt->parent_mode = vis->mode;