diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-01-13 11:59:05 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-01-13 11:59:05 +0100 |
| commit | 8ab73e6d89429ef733ec388b5ab0aa6d37fb8bef (patch) | |
| tree | ae6f7f08b7fdb054eb27078464cb1065d63d3653 | |
| parent | df0dbaa1310acceed3b73c6f74be84eceea1aace (diff) | |
| download | vis-8ab73e6d89429ef733ec388b5ab0aa6d37fb8bef.tar.gz vis-8ab73e6d89429ef733ec388b5ab0aa6d37fb8bef.tar.xz | |
vis: fix tab expansion if enabled
Closes #144
| -rw-r--r-- | vis.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -1218,8 +1218,23 @@ const char *vis_mode_status(Vis *vis) { } void vis_insert_tab(Vis *vis) { - const char *tab = expandtab(vis); - vis_insert_key(vis, tab, strlen(tab)); + if (!vis->expandtab) { + vis_insert_key(vis, "\t", 1); + return; + } + char spaces[9]; + int tabwidth = MIN(vis->tabwidth, LENGTH(spaces) - 1); + for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) { + size_t pos = view_cursors_pos(c); + /* FIXME: this does not take double width characters into account */ + int chars = text_line_char_get(vis->win->file->text, pos); + int count = tabwidth - (chars % tabwidth); + for (int i = 0; i < count; i++) + spaces[i] = ' '; + spaces[count] = '\0'; + vis_insert(vis, pos, spaces, count); + view_cursors_scroll_to(c, pos + count); + } } static void copy_indent_from_previous_line(Win *win) { |
