aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-03-27 17:05:34 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-03-28 12:25:06 +0200
commit6331bf38783810a01a233ac73fa94ed028a0e965 (patch)
tree3a8742a2c8b98113acda63a42092d583d7474384
parent64e204b205f09fdbac728c8910bf1867c286ebaa (diff)
downloadvis-6331bf38783810a01a233ac73fa94ed028a0e965.tar.gz
vis-6331bf38783810a01a233ac73fa94ed028a0e965.tar.xz
vis: align selections with <Tab> in visual mode
-rw-r--r--config.def.h1
-rw-r--r--main.c7
2 files changed, 6 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h
index 27fc4eb..827fb0c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -278,6 +278,7 @@ static const KeyBinding bindings_visual[] = {
{ "o", ACTION(SELECTION_FLIP) },
{ ">", ALIAS("<vis-operator-shift-right>gv") },
{ "<", ALIAS("<vis-operator-shift-left>gv") },
+ { "<Tab>" , ACTION(CURSORS_ALIGN_INDENT) },
{ 0 /* empty last element, array terminator */ },
};
diff --git a/main.c b/main.c
index 652ee11..4494233 100644
--- a/main.c
+++ b/main.c
@@ -1230,7 +1230,9 @@ static const char *cursors_align_indent(Vis *vis, const char *keys, const Arg *a
for (int i = 0; i < columns; i++) {
int mincol = INT_MAX, maxcol = 0;
for (Cursor *c = view_cursors_column(view, i); c; c = view_cursors_column_next(c, i)) {
- int col = text_line_width_get(txt, view_cursors_pos(c));
+ Filerange sel = view_cursors_selection_get(c);
+ size_t pos = text_range_valid(&sel) ? sel.start : view_cursors_pos(c);
+ int col = text_line_width_get(txt, pos);
if (col < mincol)
mincol = col;
if (col > maxcol)
@@ -1244,7 +1246,8 @@ static const char *cursors_align_indent(Vis *vis, const char *keys, const Arg *a
memset(buf, ' ', len);
for (Cursor *c = view_cursors_column(view, i); c; c = view_cursors_column_next(c, i)) {
- size_t pos = view_cursors_pos(c);
+ Filerange sel = view_cursors_selection_get(c);
+ size_t pos = text_range_valid(&sel) ? sel.start : view_cursors_pos(c);
int col = text_line_width_get(txt, pos);
if (col < maxcol) {
size_t off = maxcol - col;