aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-15 16:39:09 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-15 16:39:09 +0200
commit472c559a273d3c7b0f5ee92260c5544bc3d74576 (patch)
tree84f5df4e91c6ac95f35c35e0ad808e08ca8d82fe /vis.c
parent63f26c666b9497f1ea045b809a0479930498984a (diff)
downloadvis-472c559a273d3c7b0f5ee92260c5544bc3d74576.tar.gz
vis-472c559a273d3c7b0f5ee92260c5544bc3d74576.tar.xz
vis: calculate auto indent for all cursors individually
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/vis.c b/vis.c
index f069f60..d2ede55 100644
--- a/vis.c
+++ b/vis.c
@@ -1111,10 +1111,9 @@ void vis_insert_tab(Vis *vis) {
}
}
-static void copy_indent_from_previous_line(Win *win) {
- View *view = win->view;
+static void copy_indent_from_previous_line(Win *win, Cursor *cur) {
Text *text = win->file->text;
- size_t pos = view_cursor_get(view);
+ size_t pos = view_cursors_pos(cur);
size_t prev_line = text_line_prev(text, pos);
if (pos == prev_line)
return;
@@ -1125,7 +1124,8 @@ static void copy_indent_from_previous_line(Win *win) {
if (!buf)
return;
len = text_bytes_get(text, begin, len, buf);
- vis_insert_key(win->vis, buf, len);
+ text_insert(text, pos, buf, len);
+ view_cursors_scroll_to(cur, pos + len);
free(buf);
}
@@ -1133,8 +1133,11 @@ void vis_insert_nl(Vis *vis) {
const char *nl = text_newline_char(vis->win->file->text);
vis_insert_key(vis, nl, strlen(nl));
- if (vis->autoindent)
- copy_indent_from_previous_line(vis->win);
+ if (!vis->autoindent)
+ return;
+
+ for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c))
+ copy_indent_from_previous_line(vis->win, c);
}
Regex *vis_regex(Vis *vis, const char *pattern) {