aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-02-04 18:25:45 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-02-04 18:25:45 +0100
commit047047c719fd6c601629fbe13f4429b81b41d8e2 (patch)
treef331316bd2812c26de6d4d9c7588f7052135a7d8 /main.c
parentd5d8b5e6b85e5b88980ca50b2067ec33c432cb13 (diff)
downloadvis-047047c719fd6c601629fbe13f4429b81b41d8e2.tar.gz
vis-047047c719fd6c601629fbe13f4429b81b41d8e2.tar.xz
view: do not let new cursors automatically become primary
We currently have the invariant that the primary cursor is always placed within the visisble viewport. Previously view_cursors_new would automatically make the new cursor primary. This in turn causes the viewport to be adjusted triggering lots of unnecessary redraws. As a result commands creating many new selections might become unbearably slow. Instead the caller has to explicitly make the new cursor primary.
Diffstat (limited to 'main.c')
-rw-r--r--main.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/main.c b/main.c
index 2e1eeb5..40cb9c5 100644
--- a/main.c
+++ b/main.c
@@ -1321,14 +1321,15 @@ static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) {
view_line_up(cursor);
size_t newpos = view_cursors_pos(cursor);
view_cursors_to(cursor, oldpos);
- if (!view_cursors_new(view, newpos)) {
- if (arg->i == -1) {
- cursor = view_cursors_prev(cursor);
- } else if (arg->i == +1) {
- cursor = view_cursors_next(cursor);
- }
- view_cursors_primary_set(cursor);
+ Cursor *cursor_new = view_cursors_new(view, newpos);
+ if (!cursor_new) {
+ if (arg->i == -1)
+ cursor_new = view_cursors_prev(cursor);
+ else if (arg->i == +1)
+ cursor_new = view_cursors_next(cursor);
}
+ if (cursor_new)
+ view_cursors_primary_set(cursor_new);
}
vis_count_set(vis, VIS_COUNT_UNKNOWN);
return keys;
@@ -1446,6 +1447,7 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar
size_t pos = text_char_prev(txt, word.end);
if ((cursor = view_cursors_new(view, pos))) {
view_cursors_selection_set(cursor, &word);
+ view_cursors_primary_set(cursor);
goto out;
}
}
@@ -1453,8 +1455,10 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar
sel = view_cursors_selection_get(view_cursors(view));
word = text_object_word_find_prev(txt, sel.start, buf);
size_t pos = text_char_prev(txt, word.end);
- if ((cursor = view_cursors_new(view, pos)))
+ if ((cursor = view_cursors_new(view, pos))) {
view_cursors_selection_set(cursor, &word);
+ view_cursors_primary_set(cursor);
+ }
out:
free(buf);