diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-07-05 10:28:13 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-07-05 10:49:45 +0200 |
| commit | d6c4d8b155de16abcfcffa2a9bbfa886909b3ec3 (patch) | |
| tree | 8a5c1f3a399b16df9f37f8bfcb236bfee48d6e69 | |
| parent | 9b6f9c6fa71132506bc509a62b8f262a40a11700 (diff) | |
| download | vis-d6c4d8b155de16abcfcffa2a9bbfa886909b3ec3.tar.gz vis-d6c4d8b155de16abcfcffa2a9bbfa886909b3ec3.tar.xz | |
vis: make sure all selections have same anchored state
With the current model the differences between normal and visual mode
is that in the latter selections are anchored (meaning one endpoint
remains fixed), while in normal mode both endpoints can in principle
be updated simultaneously (currently they are always colapsed to a
singleton selection, giving the impression of cursors).
| -rw-r--r-- | main.c | 24 | ||||
| -rw-r--r-- | view.c | 4 | ||||
| -rw-r--r-- | view.h | 5 |
3 files changed, 23 insertions, 10 deletions
@@ -1326,6 +1326,7 @@ static const char *repeat(Vis *vis, const char *keys, const Arg *arg) { static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); + bool anchored = view_selections_anchored(view_selections_primary_get(view)); VisCountIterator it = vis_count_iterator_get(vis, 1); while (vis_count_iterator_next(&it)) { Selection *sel = NULL; @@ -1358,8 +1359,11 @@ static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) { else if (arg->i == +1) sel_new = view_selections_next(sel); } - if (sel_new) + if (sel_new) { view_selections_primary_set(sel_new); + if (anchored) + view_selections_anchor(sel_new); + } } vis_count_set(vis, VIS_COUNT_UNKNOWN); return keys; @@ -1672,9 +1676,10 @@ static const char *selections_save(Vis *vis, const char *keys, const Arg *arg) { static const char *selections_restore(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); + bool anchored = view_selections_anchored(view_selections_primary_get(view)); enum VisRegister reg = vis_register_used(vis); Array sel = vis_register_selections_get(vis, reg); - view_selections_set_all(view, &sel); + view_selections_set_all(view, &sel, anchored); array_release(&sel); vis_cancel(vis); return keys; @@ -1707,6 +1712,7 @@ static void normalize(Array *a) { static const char *selections_union(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); + bool anchored = view_selections_anchored(view_selections_primary_get(view)); enum VisRegister reg = vis_register_used(vis); Array a = vis_register_selections_get(vis, reg); Array b = view_selections_get_all(view); @@ -1746,7 +1752,7 @@ static const char *selections_union(Vis *vis, const char *keys, const Arg *arg) if (text_range_valid(&cur)) array_add(&sel, &cur); - view_selections_set_all(view, &sel); + view_selections_set_all(view, &sel, anchored); vis_cancel(vis); array_release(&a); @@ -1773,6 +1779,7 @@ static void intersect(Array *ret, Array *a, Array *b) { static const char *selections_intersect(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); + bool anchored = view_selections_anchored(view_selections_primary_get(view)); enum VisRegister reg = vis_register_used(vis); Array a = vis_register_selections_get(vis, reg); Array b = view_selections_get_all(view); @@ -1780,7 +1787,7 @@ static const char *selections_intersect(Vis *vis, const char *keys, const Arg *a array_init_from(&sel, &a); intersect(&sel, &a, &b); - view_selections_set_all(view, &sel); + view_selections_set_all(view, &sel, anchored); vis_cancel(vis); array_release(&a); @@ -1809,6 +1816,7 @@ static void complement(Array *ret, Array *a, Filerange *universe) { static const char *selections_complement(Vis *vis, const char *keys, const Arg *arg) { Text *txt = vis_text(vis); View *view = vis_view(vis); + bool anchored = view_selections_anchored(view_selections_primary_get(view)); Filerange universe = text_object_entire(txt, 0); Array a = view_selections_get_all(view); Array sel; @@ -1816,7 +1824,7 @@ static const char *selections_complement(Vis *vis, const char *keys, const Arg * complement(&sel, &a, &universe); - view_selections_set_all(view, &sel); + view_selections_set_all(view, &sel, anchored); array_release(&a); array_release(&sel); return keys; @@ -1824,6 +1832,7 @@ static const char *selections_complement(Vis *vis, const char *keys, const Arg * static const char *selections_minus(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); + bool anchored = view_selections_anchored(view_selections_primary_get(view)); enum VisRegister reg = vis_register_used(vis); Array a = view_selections_get_all(view); Array b = vis_register_selections_get(vis, reg); @@ -1839,7 +1848,7 @@ static const char *selections_minus(Vis *vis, const char *keys, const Arg *arg) complement(&b_complement, &b, &universe); intersect(&sel, &a, &b_complement); - view_selections_set_all(view, &sel); + view_selections_set_all(view, &sel, anchored); vis_cancel(vis); array_release(&a); @@ -1902,6 +1911,7 @@ static Filerange combine_rightmost(const Filerange *r1, const Filerange *r2) { static const char *selections_combine(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); + bool anchored = view_selections_anchored(view_selections_primary_get(view)); enum VisRegister reg = vis_register_used(vis); Array a = view_selections_get_all(view); Array b = vis_register_selections_get(vis, reg); @@ -1916,7 +1926,7 @@ static const char *selections_combine(Vis *vis, const char *keys, const Arg *arg } normalize(&sel); - view_selections_set_all(view, &sel); + view_selections_set_all(view, &sel, anchored); vis_cancel(vis); array_release(&a); @@ -1252,7 +1252,7 @@ bool view_regions_save(View *view, Filerange *r, SelectionRegion *s) { return true; } -void view_selections_set_all(View *view, Array *arr) { +void view_selections_set_all(View *view, Array *arr, bool anchored) { Selection *s; Filerange *r; size_t i = 0; @@ -1264,11 +1264,13 @@ void view_selections_set_all(View *view, Array *arr) { } break; } + s->anchored = anchored; } while ((r = array_get(arr, i++))) { s = view_selections_new_force(view, r->start); if (!s || !view_selections_set(s, r)) break; + s->anchored = anchored; } view_selections_primary_set(view->selections); } @@ -147,9 +147,10 @@ void view_selections_dispose_all(View*); void view_selections_normalize(View*); /** * Replace currently active selections. - * @param The array of ``Filerange``s. + * @param array The Array of ``Filerange``s. + * @param anchored Whether *all* selection should be anchored. */ -void view_selections_set_all(View*, Array*); +void view_selections_set_all(View*, Array*, bool anchored); /** Get array containing a ``Fileranges`` for each selection. */ Array view_selections_get_all(View*); /** |
