diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-28 10:41:55 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-03-28 12:25:06 +0200 |
| commit | d970c893a253785f4fa8d99f306d6d891702fc6d (patch) | |
| tree | 250bb75cfaf9a3e7a627a35b7ab49c24a2dbe94f /main.c | |
| parent | a7a05a70c3c51c4fe565598e9508d0505a758636 (diff) | |
| download | vis-d970c893a253785f4fa8d99f306d6d891702fc6d.tar.gz vis-d970c893a253785f4fa8d99f306d6d891702fc6d.tar.xz | |
vis: support right alignment of selections in visual mode with <S-Tab>
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 33 |
1 files changed, 25 insertions, 8 deletions
@@ -245,7 +245,8 @@ enum { VIS_ACTION_CURSORS_NEW_MATCH_NEXT, VIS_ACTION_CURSORS_NEW_MATCH_SKIP, VIS_ACTION_CURSORS_ALIGN, - VIS_ACTION_CURSORS_ALIGN_INDENT, + VIS_ACTION_CURSORS_ALIGN_INDENT_LEFT, + VIS_ACTION_CURSORS_ALIGN_INDENT_RIGHT, VIS_ACTION_CURSORS_REMOVE_ALL, VIS_ACTION_CURSORS_REMOVE_LAST, VIS_ACTION_CURSORS_PREV, @@ -930,10 +931,15 @@ static const KeyAction vis_action[] = { "Try to align all cursors on the same column", cursors_align, }, - [VIS_ACTION_CURSORS_ALIGN_INDENT] = { - "cursors-align-indent", - "Try to align all cursors by inserting spaces", - cursors_align_indent, + [VIS_ACTION_CURSORS_ALIGN_INDENT_LEFT] = { + "cursors-align-indent-left", + "Left align all cursors/selections by inserting spaces", + cursors_align_indent, { .i = -1 } + }, + [VIS_ACTION_CURSORS_ALIGN_INDENT_RIGHT] = { + "cursors-align-indent-right", + "Right align all cursors/selections by inserting spaces", + cursors_align_indent, { .i = +1 } }, [VIS_ACTION_CURSORS_REMOVE_ALL] = { "cursors-remove-all", @@ -1260,8 +1266,12 @@ 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)) { + size_t pos; Filerange sel = view_cursors_selection_get(c); - size_t pos = text_range_valid(&sel) ? sel.start : view_cursors_pos(c); + if (text_range_valid(&sel)) + pos = left_align ? sel.start : sel.end; + else + pos = view_cursors_pos(c); int col = text_line_width_get(txt, pos); if (col < mincol) mincol = col; @@ -1276,13 +1286,20 @@ 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, ipos; Filerange sel = view_cursors_selection_get(c); - size_t pos = text_range_valid(&sel) ? sel.start : view_cursors_pos(c); + if (text_range_valid(&sel)) { + pos = left_align ? sel.start : sel.end; + ipos = sel.start; + } else { + pos = view_cursors_pos(c); + ipos = pos; + } int col = text_line_width_get(txt, pos); if (col < maxcol) { size_t off = maxcol - col; if (off <= len) - text_insert(txt, pos, buf, off); + text_insert(txt, ipos, buf, off); } } |
