aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-06-10 15:03:46 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-06-15 15:51:42 +0200
commit708216769c7cdf02ce3f69785a4356efd7dea0f7 (patch)
tree19f8faad6ff334d3d09d1f41ab1070a52bdbc54c /vis.c
parent0df87384ac791bbf85cf4b3d386fb851e5b87de4 (diff)
downloadvis-708216769c7cdf02ce3f69785a4356efd7dea0f7.tar.gz
vis-708216769c7cdf02ce3f69785a4356efd7dea0f7.tar.xz
vis: promote selections to first class primitives
This unifies cursors and selections. The cursor are now represendted as singleton selections.
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c33
1 files changed, 8 insertions, 25 deletions
diff --git a/vis.c b/vis.c
index b689e6f..2455a59 100644
--- a/vis.c
+++ b/vis.c
@@ -245,10 +245,15 @@ void vis_window_status(Win *win, const char *status) {
}
void window_selection_save(Win *win) {
+ Vis *vis = win->vis;
File *file = win->file;
Filerange sel = view_cursors_selection_get(view_cursors(win->view));
file->marks[VIS_MARK_SELECTION_START] = text_mark_set(file->text, sel.start);
file->marks[VIS_MARK_SELECTION_END] = text_mark_set(file->text, sel.end);
+ if (!vis->action.op) {
+ for (Selection *s = view_cursors(win->view); s; s = view_cursors_next(s))
+ view_cursors_selection_save(s);
+ }
}
static void window_free(Win *win) {
@@ -966,39 +971,17 @@ void vis_do(Vis *vis) {
if (linewise && vis->mode != &vis_modes[VIS_MODE_VISUAL])
c.range = text_range_linewise(txt, &c.range);
- if (vis->mode->visual) {
+ if (vis->mode->visual)
view_cursors_selection_set(cursor, &c.range);
- if (vis->mode == &vis_modes[VIS_MODE_VISUAL] || a->textobj)
- view_cursors_selection_sync(cursor);
- }
if (a->op) {
size_t pos = a->op->func(vis, txt, &c);
if (pos == EPOS) {
view_cursors_dispose(cursor);
} else if (pos <= text_size(txt)) {
- /* moving the cursor will affect the selection.
- * because we want to be able to later restore
- * the old selection we update it again before
- * leaving visual mode.
- */
- Filerange sel = view_cursors_selection_get(cursor);
+ if (vis->mode->visual)
+ view_cursors_selection_save(cursor);
view_cursors_to(cursor, pos);
- if (vis->mode->visual) {
- if (sel.start == EPOS && sel.end == EPOS)
- sel = c.range;
- else if (sel.start == EPOS)
- sel = text_range_new(c.range.start, sel.end);
- else if (sel.end == EPOS)
- sel = text_range_new(c.range.start, sel.start);
- if (vis->mode == &vis_modes[VIS_MODE_VISUAL_LINE])
- sel = text_range_linewise(txt, &sel);
- if (!text_range_contains(&sel, pos)) {
- Filerange cur = text_range_new(pos, pos);
- sel = text_range_union(&sel, &cur);
- }
- view_cursors_selection_set(cursor, &sel);
- }
}
}
}