diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-10 22:18:09 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-03-10 22:36:54 +0100 |
| commit | 054f792ac6c1502d5f9bb2b251b3f96c4cb27f6b (patch) | |
| tree | 161d42f53cf794840c795ad5d2d1b900c51f99b9 | |
| parent | 0e322d577bf834d8f7c9a7d3c53a58f8e7bb93c1 (diff) | |
| download | vis-054f792ac6c1502d5f9bb2b251b3f96c4cb27f6b.tar.gz vis-054f792ac6c1502d5f9bb2b251b3f96c4cb27f6b.tar.xz | |
view: add query function for multiple cursors
| -rw-r--r-- | main.c | 9 | ||||
| -rw-r--r-- | ui-curses.c | 2 | ||||
| -rw-r--r-- | view.c | 4 | ||||
| -rw-r--r-- | view.h | 2 |
4 files changed, 11 insertions, 6 deletions
@@ -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 35d43c8..44dd18e 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; @@ -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; @@ -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*); |
