Skip to content

Commit

Permalink
vis: use distinct mark to save last selections
Browse files Browse the repository at this point in the history
This partially reverts f9e2b88
further jumps after leaving visual mode should not break `gv`.
  • Loading branch information
martanne committed Jul 14, 2017
1 parent bacf932 commit 57dcdd6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions vis-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct Win {
File *file; /* file being displayed in this window */
View *view; /* currently displayed part of underlying text */
MarkList jumplist; /* LRU jump management */
Array saved_selections; /* register used to store selections */
Mode modes[VIS_MODE_INVALID]; /* overlay mods used for per window key bindings */
Win *parent; /* window which was active when showing the command prompt */
Mode *parent_mode; /* mode which was active when showing the command prompt */
Expand Down Expand Up @@ -264,6 +265,7 @@ Mode *mode_get(Vis*, enum VisMode);
void mode_set(Vis *vis, Mode *new_mode);
Macro *macro_get(Vis *vis, enum VisRegister);

void window_selection_save(Win *win);
Win *window_new_file(Vis*, File*, enum UiOption);

const char *file_name_get(File*);
Expand Down
2 changes: 1 addition & 1 deletion vis-marks.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void mark_release(Array *arr) {

static Array *mark_from(Vis *vis, enum VisMark id) {
if (id == VIS_MARK_SELECTION && vis->win)
return array_peek(&vis->win->jumplist.prev);
return &vis->win->saved_selections;
File *file = vis->win->file;
if (id < LENGTH(file->marks))
return &file->marks[id];
Expand Down
4 changes: 2 additions & 2 deletions vis-modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ 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) {
if (!vis->action.op)
vis_jumplist_save(vis);
window_selection_save(vis->win);
view_selections_clear_all(vis->win->view);
} else {
view_cursor_to(vis->win->view, view_cursor_get(vis->win->view));
Expand All @@ -212,7 +212,7 @@ static void vis_mode_visual_line_leave(Vis *vis, Mode *new) {
static void vis_mode_visual_leave(Vis *vis, Mode *new) {
if (!new->visual) {
if (!vis->action.op)
vis_jumplist_save(vis);
window_selection_save(vis->win);
view_selections_clear_all(vis->win->view);
}
}
Expand Down
14 changes: 13 additions & 1 deletion vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ void vis_window_status(Win *win, const char *status) {
win->ui->status(win->ui, status);
}

void window_selection_save(Win *win) {
Vis *vis = win->vis;
View *view = win->view;
Array sel = view_selections_get_all(view);
vis_mark_set(vis, VIS_MARK_SELECTION, &sel);
array_release(&sel);
vis_jumplist_save(vis);
}


static void window_free(Win *win) {
if (!win)
return;
Expand All @@ -257,6 +267,7 @@ static void window_free(Win *win) {
for (size_t i = 0; i < LENGTH(win->modes); i++)
map_free(win->modes[i].bindings);
marklist_release(&win->jumplist);
mark_release(&win->saved_selections);
free(win);
}

Expand Down Expand Up @@ -454,6 +465,7 @@ Win *window_new_file(Vis *vis, File *file, enum UiOption options) {
return NULL;
}
marklist_init(&win->jumplist, 32);
mark_init(&win->saved_selections);
file->refcount++;
view_options_set(win->view, view_options_get(win->view));
view_tabwidth_set(win->view, vis->tabwidth);
Expand Down Expand Up @@ -822,7 +834,7 @@ void vis_do(Vis *vis) {
reg_slot = 0;

if (vis->mode->visual && a->op)
vis_jumplist_save(vis);
window_selection_save(win);

for (Selection *sel = view_selections(view), *next; sel; sel = next) {
if (vis->interrupted)
Expand Down

0 comments on commit 57dcdd6

Please sign in to comment.