aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-13 17:37:29 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-13 17:54:48 +0200
commit6eca958b2e72b7a264e86ec35cd5119d975ee251 (patch)
tree7f9819fbb17b2ed10c5e1564b1bcc1c1db7a5d72
parent1a158268c7693b00bf43c7e81034816d8d00358c (diff)
downloadvis-6eca958b2e72b7a264e86ec35cd5119d975ee251.tar.gz
vis-6eca958b2e72b7a264e86ec35cd5119d975ee251.tar.xz
vis: stop repeated motions as soon as resulting position remains the same
This improves responsiveness of {count}j for files with less than count lines. For huge files this will still be slow because the code tries to restore cursor position on every line before moving on to the next. Also moving up will generally be slower than downwards. Use {count}% (fastest) or or :count (slower) instead. Close #267
-rw-r--r--vis.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/vis.c b/vis.c
index 730763b..4926555 100644
--- a/vis.c
+++ b/vis.c
@@ -495,6 +495,7 @@ void action_do(Vis *vis, Action *a) {
if (a->movement) {
size_t start = pos;
for (int i = 0; i < count; i++) {
+ size_t pos_prev = pos;
if (a->movement->txt)
pos = a->movement->txt(txt, pos);
else if (a->movement->cur)
@@ -509,7 +510,7 @@ void action_do(Vis *vis, Action *a) {
pos = a->movement->win(vis, win, pos);
else if (a->movement->user)
pos = a->movement->user(vis, win, a->movement->data, pos);
- if (pos == EPOS || a->movement->type & IDEMPOTENT)
+ if (pos == EPOS || a->movement->type & IDEMPOTENT || pos == pos_prev)
break;
}