aboutsummaryrefslogtreecommitdiff
path: root/vis-modes.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-11-28 18:37:29 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-11-28 20:09:14 +0100
commit30e9673fdb22905df853ef07b3826fa19b28831c (patch)
tree1b5fba8cdd110228df92972660eab026ab1e879a /vis-modes.c
parentd6a2d5bea9364dfecefecef084671b2c7fc1dc8a (diff)
downloadvis-30e9673fdb22905df853ef07b3826fa19b28831c.tar.gz
vis-30e9673fdb22905df853ef07b3826fa19b28831c.tar.xz
vis: improve switching to prompt mode
A call to vis_prompt_show will now automatically switch to prompt mode. Within the prompt leave/enter handlers the focused window (vis->win) will still point to the document window not the one referring to the prompt. The selection marks '< and '> are now only updated when a visual mode is left.
Diffstat (limited to 'vis-modes.c')
-rw-r--r--vis-modes.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/vis-modes.c b/vis-modes.c
index 9da5009..f1f8343 100644
--- a/vis-modes.c
+++ b/vis-modes.c
@@ -64,16 +64,20 @@ static void vis_mode_operator_input(Vis *vis, const char *str, size_t len) {
static void vis_mode_visual_enter(Vis *vis, Mode *old) {
if (!old->visual) {
- for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c))
- view_cursors_selection_start(c);
+ if (old != &vis_modes[VIS_MODE_PROMPT]) {
+ for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c))
+ view_cursors_selection_start(c);
+ }
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_TEXTOBJ];
}
}
static void vis_mode_visual_line_enter(Vis *vis, Mode *old) {
if (!old->visual) {
- for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c))
- view_cursors_selection_start(c);
+ if (old != &vis_modes[VIS_MODE_PROMPT]) {
+ for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c))
+ view_cursors_selection_start(c);
+ }
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_TEXTOBJ];
}
vis_motion(vis, VIS_MOVE_LINE_END);
@@ -81,8 +85,13 @@ static void vis_mode_visual_line_enter(Vis *vis, Mode *old) {
static void vis_mode_visual_line_leave(Vis *vis, Mode *new) {
if (!new->visual) {
- view_selections_clear(vis->win->view);
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_MOVE];
+ File *file = vis->win->file;
+ Filerange sel = view_cursors_selection_get(view_cursors(vis->win->view));
+ file->marks[MARK_SELECTION_START] = text_mark_set(file->text, sel.start);
+ file->marks[MARK_SELECTION_END] = text_mark_set(file->text, sel.end);
+ if (new != &vis_modes[VIS_MODE_PROMPT])
+ view_selections_clear(vis->win->view);
} else {
view_cursor_to(vis->win->view, view_cursor_get(vis->win->view));
}
@@ -90,8 +99,13 @@ static void vis_mode_visual_line_leave(Vis *vis, Mode *new) {
static void vis_mode_visual_leave(Vis *vis, Mode *new) {
if (!new->visual) {
- view_selections_clear(vis->win->view);
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_MOVE];
+ File *file = vis->win->file;
+ Filerange sel = view_cursors_selection_get(view_cursors(vis->win->view));
+ file->marks[MARK_SELECTION_START] = text_mark_set(file->text, sel.start);
+ file->marks[MARK_SELECTION_END] = text_mark_set(file->text, sel.end);
+ if (new != &vis_modes[VIS_MODE_PROMPT])
+ view_selections_clear(vis->win->view);
}
}