Skip to content

Commit

Permalink
view: add query function for multiple cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Mar 10, 2016
1 parent 0e322d5 commit 054f792
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
9 changes: 4 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ui-curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down

0 comments on commit 054f792

Please sign in to comment.