vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit b960e6f06fc8759bf46722385033d9cdc1166808
parent 2b7166d700668ae2ed9db1c2bc45487543faf65b
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu,  7 Apr 2016 17:54:12 +0200

vis: cleanup window focusing code

Diffstat:
Mvis.c | 21+++++++++++++--------
Mvis.h | 2++
2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/vis.c b/vis.c @@ -226,24 +226,29 @@ bool vis_window_split(Win *original) { return true; } +void vis_window_focus(Win *win) { + if (!win) + return; + Vis *vis = win->vis; + vis->win = win; + vis->ui->window_focus(win->ui); +} + void vis_window_next(Vis *vis) { Win *sel = vis->win; if (!sel) return; - vis->win = vis->win->next; - if (!vis->win) - vis->win = vis->windows; - vis->ui->window_focus(vis->win->ui); + vis_window_focus(sel->next ? sel->next : vis->windows); } void vis_window_prev(Vis *vis) { Win *sel = vis->win; if (!sel) return; - vis->win = vis->win->prev; - if (!vis->win) - for (vis->win = vis->windows; vis->win->next; vis->win = vis->win->next); - vis->ui->window_focus(vis->win->ui); + sel = sel->prev; + if (!sel) + for (sel = vis->windows; sel->next; sel = sel->next); + vis_window_focus(sel); } void vis_draw(Vis *vis) { diff --git a/vis.h b/vis.h @@ -81,6 +81,8 @@ void vis_window_name(Win*, const char *filename); /* focus the next / previous window */ void vis_window_next(Vis*); void vis_window_prev(Vis*); +/* change currently focused window, receiving user input */ +void vis_window_focus(Win*); /* display a user prompt with a certain title and default text */ void vis_prompt_show(Vis*, const char *title);