diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-30 19:57:35 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-30 19:57:35 +0200 |
| commit | 14ab569ac03d5fd1e641948dbfc3decd5b74421c (patch) | |
| tree | dec101004d1650ef85a484d9985cdcbb61e59d2a | |
| parent | bd3176f1881402e5c50d060eb8d1f9317e45c472 (diff) | |
| download | vis-14ab569ac03d5fd1e641948dbfc3decd5b74421c.tar.gz vis-14ab569ac03d5fd1e641948dbfc3decd5b74421c.tar.xz | |
Clean up visual mode handling
| -rw-r--r-- | config.def.h | 10 | ||||
| -rw-r--r-- | vis.c | 7 |
2 files changed, 10 insertions, 7 deletions
diff --git a/config.def.h b/config.def.h index 69b2ff8..99148ce 100644 --- a/config.def.h +++ b/config.def.h @@ -427,12 +427,12 @@ static KeyBinding vis_mode_visual[] = { }; static void vis_mode_visual_enter(Mode *old) { - if (old != &vis_modes[VIS_MODE_VISUAL_LINE]) + if (!old->visual) window_selection_start(vis->win->win); } static void vis_mode_visual_leave(Mode *new) { - if (new != &vis_modes[VIS_MODE_VISUAL_LINE]) + if (!new->visual) window_selection_clear(vis->win->win); } @@ -445,13 +445,13 @@ static KeyBinding vis_mode_visual_line[] = { static void vis_mode_visual_line_enter(Mode *old) { Win *win = vis->win->win; window_cursor_to(win, text_line_begin(vis->win->text, window_cursor_get(win))); - if (old != &vis_modes[VIS_MODE_VISUAL]) + if (!old->visual) window_selection_start(vis->win->win); movement(&(const Arg){ .i = MOVE_LINE_END }); } static void vis_mode_visual_line_leave(Mode *new) { - if (new != &vis_modes[VIS_MODE_VISUAL]) + if (!new->visual) window_selection_clear(vis->win->win); } @@ -676,6 +676,7 @@ static Mode vis_modes[] = { .bindings = vis_mode_visual, .enter = vis_mode_visual_enter, .leave = vis_mode_visual_leave, + .visual = true, }, [VIS_MODE_VISUAL_LINE] = { .name = "--VISUAL LINE--", @@ -683,6 +684,7 @@ static Mode vis_modes[] = { .bindings = vis_mode_visual_line, .enter = vis_mode_visual_line_enter, .leave = vis_mode_visual_line_leave, + .visual = true, }, [VIS_MODE_READLINE] = { .name = "READLINE", @@ -76,6 +76,7 @@ struct Mode { void (*input)(const char*, size_t); /* called whenever a key is not found in this mode and all its parent modes */ void (*idle)(void); /* called whenever a certain idle time i.e. without any user input elapsed */ time_t idle_timeout; /* idle time in seconds after which the registered function will be called */ + bool visual; /* whether text selection is possible in this mode */ }; typedef struct { @@ -809,7 +810,7 @@ static void linewise(const Arg *arg) { static void operator(const Arg *arg) { Operator *op = &ops[arg->i]; - if (mode == &vis_modes[VIS_MODE_VISUAL] || mode == &vis_modes[VIS_MODE_VISUAL_LINE]) { + if (mode->visual) { action.op = op; action_do(&action); return; @@ -1152,7 +1153,7 @@ static void action_do(Action *a) { } } } - } else if (mode == &vis_modes[VIS_MODE_VISUAL] || mode == &vis_modes[VIS_MODE_VISUAL_LINE]) { + } else if (mode->visual) { c.range = window_selection_get(win); if (!text_range_valid(&c.range)) c.range.start = c.range.end = pos; @@ -1162,7 +1163,7 @@ static void action_do(Action *a) { a->op->func(&c); if (mode == &vis_modes[VIS_MODE_OPERATOR]) switchmode_to(mode_prev); - else if (mode == &vis_modes[VIS_MODE_VISUAL] || mode == &vis_modes[VIS_MODE_VISUAL_LINE]) + else if (mode->visual) switchmode(&(const Arg){ .i = VIS_MODE_NORMAL }); text_snapshot(txt); } |
