From f9e2b884c15919757651db8b10c033a344a19e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 10 Jul 2017 18:23:47 +0200 Subject: vis: let '^ mark point to top of jump list --- vis-core.h | 2 -- vis-marks.c | 15 +++++++-------- vis-modes.c | 4 ++-- vis-prompt.c | 2 -- vis.c | 12 +----------- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/vis-core.h b/vis-core.h index 9c6a635..cb384a4 100644 --- a/vis-core.h +++ b/vis-core.h @@ -166,7 +166,6 @@ struct Win { View *view; /* currently displayed part of underlying text */ MarkList jumplist; /* LRU jump management */ ChangeList changelist; /* state for iterating through least recently changes */ - 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 */ @@ -272,7 +271,6 @@ 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*); diff --git a/vis-marks.c b/vis-marks.c index e04f6b0..7543792 100644 --- a/vis-marks.c +++ b/vis-marks.c @@ -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 &vis->win->saved_selections; + return array_peek(&vis->win->jumplist.prev); File *file = vis->win->file; if (id < LENGTH(file->marks)) return &file->marks[id]; @@ -105,8 +105,11 @@ void vis_mark_set(Vis *vis, enum VisMark id, Array *sel) { } void marklist_init(MarkList *list, size_t max) { + Array mark; + mark_init(&mark); array_init_sized(&list->prev, sizeof(Array)); array_reserve(&list->prev, max); + array_add(&list->prev, &mark); array_init_sized(&list->next, sizeof(Array)); array_reserve(&list->next, max); } @@ -168,14 +171,10 @@ static bool marklist_prev(Win *win, MarkList *list) { if (restore) goto out; - for (;;) { + while (array_length(&list->prev) > 1) { Array *prev = array_pop(&list->prev); - if (!prev) - goto out; array_push(&list->next, prev); prev = array_peek(&list->prev); - if (!prev) - goto out; Array sel = mark_get(win, prev); restore = array_length(&sel) > 0; if (restore) @@ -226,6 +225,6 @@ enum VisMark vis_mark_from(Vis *vis, char mark) { } const MarkDef vis_marks[] = { - [VIS_MARK_DEFAULT] = { '\'', VIS_HELP("Default mark") }, - [VIS_MARK_SELECTION] = { '^', VIS_HELP("Last selections") }, + [VIS_MARK_DEFAULT] = { '\'', VIS_HELP("Default mark") }, + [VIS_MARK_SELECTION] = { '^', VIS_HELP("Last selections") }, }; diff --git a/vis-modes.c b/vis-modes.c index d6ea134..4aa6949 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -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) - window_selection_save(vis->win); + vis_jumplist_save(vis); view_selections_clear_all(vis->win->view); } else { view_cursor_to(vis->win->view, view_cursor_get(vis->win->view)); @@ -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) - window_selection_save(vis->win); + vis_jumplist_save(vis); view_selections_clear_all(vis->win->view); } } diff --git a/vis-prompt.c b/vis-prompt.c index dc1cc13..d3e9b8e 100644 --- a/vis-prompt.c +++ b/vis-prompt.c @@ -165,8 +165,6 @@ void vis_prompt_show(Vis *vis, const char *title) { UI_OPTION_ONELINE); if (!prompt) return; - if (vis->mode->visual) - window_selection_save(active); Text *txt = prompt->file->text; text_appendf(txt, "%s\n", title); Selection *sel = view_selections_primary_get(prompt->view); diff --git a/vis.c b/vis.c index 375e73a..7596097 100644 --- a/vis.c +++ b/vis.c @@ -243,14 +243,6 @@ 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); -} - static void window_free(Win *win) { if (!win) return; @@ -265,7 +257,6 @@ 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); } @@ -463,7 +454,6 @@ 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); @@ -832,7 +822,7 @@ void vis_do(Vis *vis) { reg_slot = 0; if (vis->mode->visual && a->op) - window_selection_save(win); + vis_jumplist_save(vis); for (Selection *sel = view_selections(view), *next; sel; sel = next) { if (vis->interrupted) -- cgit v1.2.3