aboutsummaryrefslogtreecommitdiff
path: root/vis-marks.c
diff options
context:
space:
mode:
authorRandy Palamar <randy@rnpnr.xyz>2025-12-17 17:19:10 -0700
committerRandy Palamar <randy@rnpnr.xyz>2026-01-06 15:54:04 -0700
commit6ced61ef5f366001877823ed8aff978035fa53c8 (patch)
tree23487e77c00326e6fca9bb31beb4aff0ede92f14 /vis-marks.c
parent65d0847af82ba6189817dfab4485de111e299634 (diff)
downloadvis-6ced61ef5f366001877823ed8aff978035fa53c8.tar.gz
vis-6ced61ef5f366001877823ed8aff978035fa53c8.tar.xz
vis-marks: make mark set cache actually useful
Without also saving and restoring the editor mode when the selections were added to the cache almost no useful actions can be performed. While we are at it the 3 jumplist functions can just be combined into one.
Diffstat (limited to 'vis-marks.c')
-rw-r--r--vis-marks.c66
1 files changed, 23 insertions, 43 deletions
diff --git a/vis-marks.c b/vis-marks.c
index a44e727..083d331 100644
--- a/vis-marks.c
+++ b/vis-marks.c
@@ -104,59 +104,39 @@ void vis_mark_set(Win *win, enum VisMark id, Array *sel) {
mark_set(win, mark_from(win->vis, id), sel);
}
-void vis_jumplist_save(Vis *vis)
-{
- Win *win = vis->win;
- Array sel = view_selections_get_all(&win->view);
- Array *top = win->mark_set_lru + (win->mark_set_lru_cursor % LENGTH(win->mark_set_lru));
- bool done = false;
- if (top->len) {
- Array top_sel = mark_get(win, top);
- /* NOTE: avoid pushing duplicate sets into cache */
- done = vis_mark_equal(&top_sel, &sel);
- array_release(&top_sel);
- }
-
- if (!done) {
- Array *arr = win->mark_set_lru + (win->mark_set_lru_cursor++ % LENGTH(win->mark_set_lru));
- mark_set(win, arr, &sel);
- }
-
- array_release(&sel);
-}
-
-void vis_jumplist_prev(Vis *vis)
+void vis_jumplist(Vis *vis, int advance)
{
Win *win = vis->win;
View *view = &win->view;
Array cur = view_selections_get_all(view);
- bool anchored = view_selections_primary_get(view)->anchored;
- Array *top = win->mark_set_lru + (--win->mark_set_lru_cursor % LENGTH(win->mark_set_lru));
- if (top->len) {
- Array sel = mark_get(win, top);
- if (!vis_mark_equal(top, &cur)) {
- view_selections_set_all(view, &sel, anchored);
- }
- array_release(&sel);
- }
- array_release(&cur);
-}
-
-void vis_jumplist_next(Vis *vis)
-{
- Win *win = vis->win;
- View *view = &win->view;
- bool anchored = view_selections_primary_get(view)->anchored;
- Array *next = win->mark_set_lru + (win->mark_set_lru_cursor++ % LENGTH(win->mark_set_lru));
+ size_t cursor = win->mark_set_lru_cursor;
+ win->mark_set_lru_cursor += advance;
+ if (advance < 0)
+ cursor = win->mark_set_lru_cursor;
+ cursor %= VIS_MARK_SET_LRU_COUNT;
+ Array *next = win->mark_set_lru_regions + cursor;
+ bool done = false;
if (next->len) {
Array sel = mark_get(win, next);
- if (sel.len > 0) {
- view_selections_set_all(view, &sel, anchored);
- array_release(&sel);
+ done = vis_mark_equal(&sel, &cur);
+ if (advance && !done) {
+ /* NOTE: set cached selection */
+ vis_mode_switch(vis, win->mark_set_lru_modes[cursor]);
+ view_selections_set_all(view, &sel, view_selections_primary_get(view)->anchored);
}
+ array_release(&sel);
+ }
+
+ if (!advance && !done) {
+ /* NOTE: save the current selection */
+ mark_set(win, next, &cur);
+ win->mark_set_lru_modes[cursor] = vis->mode->id;
+ win->mark_set_lru_cursor++;
}
+
+ array_release(&cur);
}
enum VisMark vis_mark_from(Vis *vis, char mark) {