From 054f792ac6c1502d5f9bb2b251b3f96c4cb27f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 10 Mar 2016 22:18:09 +0100 Subject: [PATCH] view: add query function for multiple cursors --- main.c | 9 ++++----- ui-curses.c | 2 +- view.c | 4 ++++ view.h | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index bb6f8cf67..11d55e48b 100644 --- a/main.c +++ b/main.c @@ -1253,7 +1253,7 @@ static const char *cursors_align_indent(Vis *vis, const char *keys, const Arg *a static const char *cursors_clear(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - if (view_cursors_count(view) > 1) + if (view_cursors_multiple(view)) view_cursors_clear(view); else view_cursors_selection_clear(view_cursors_primary_get(view)); @@ -1317,8 +1317,7 @@ static const char *cursors_remove(Vis *vis, const char *keys, const Arg *arg) { static const char *cursors_navigate(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - bool multiple_cursors = view_cursors_next(view_cursors(view)); - if (!multiple_cursors) + if (!view_cursors_multiple(view)) return wscroll(vis, keys, arg); Cursor *c = view_cursors_primary_get(view); if (arg->i < 0) { @@ -1471,7 +1470,7 @@ static const char *undo(Vis *vis, const char *keys, const Arg *arg) { size_t pos = text_undo(vis_text(vis)); if (pos != EPOS) { View *view = vis_view(vis); - if (view_cursors_count(view) == 1) + if (!view_cursors_multiple(view)) view_cursor_to(view, pos); /* redraw all windows in case some display the same file */ vis_draw(vis); @@ -1483,7 +1482,7 @@ static const char *redo(Vis *vis, const char *keys, const Arg *arg) { size_t pos = text_redo(vis_text(vis)); if (pos != EPOS) { View *view = vis_view(vis); - if (view_cursors_count(view) == 1) + if (!view_cursors_multiple(view)) view_cursor_to(view, pos); /* redraw all windows in case some display the same file */ vis_draw(vis); diff --git a/ui-curses.c b/ui-curses.c index 35d43c86d..44dd18e62 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -683,7 +683,7 @@ static void ui_window_draw(UiWin *w) { } short selection_bg = win->styles[UI_STYLE_SELECTION].bg; short cursor_line_bg = win->styles[UI_STYLE_CURSOR_LINE].bg; - bool multiple_cursors = view_cursors_next(view_cursors(win->view)); + bool multiple_cursors = view_cursors_multiple(win->view); attr_t attr = A_NORMAL; for (const Line *l = view_lines_get(win->view); l; l = l->next) { bool cursor_line = l->lineno == cursor_lineno; diff --git a/view.c b/view.c index 05fbaf37d..4b2f7c8dd 100644 --- a/view.c +++ b/view.c @@ -1090,6 +1090,10 @@ int view_cursors_count(View *view) { return i; } +bool view_cursors_multiple(View *view) { + return view->cursors && view->cursors->next; +} + static void view_cursors_free(Cursor *c) { if (!c) return; diff --git a/view.h b/view.h index f2e30eb80..81e82f5fe 100644 --- a/view.h +++ b/view.h @@ -123,6 +123,8 @@ void view_cursor_to(View*, size_t pos); Cursor *view_cursors_new(View*); /* get number of active cursors */ int view_cursors_count(View*); +/* exist there more than 1 cursor */ +bool view_cursors_multiple(View*); /* dispose an existing cursor with its associated selection (if any), * not applicaple for the last existing cursor */ void view_cursors_dispose(Cursor*);