aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-18 18:11:49 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-18 18:11:49 +0200
commit286a09e486e0f4f0417bc3a411b9a07ffa50f3e1 (patch)
tree3c56bd0d49fe29f19c6a3726583efcc9f9b1c4f7 /vis.c
parent1e39c1cd8b02d58b744e9cb35df4ca41f68d5f79 (diff)
downloadvis-286a09e486e0f4f0417bc3a411b9a07ffa50f3e1.tar.gz
vis-286a09e486e0f4f0417bc3a411b9a07ffa50f3e1.tar.xz
Cleanup handling of action.count
If no multiplier is given action.count is zero. This fixes 1G vs G.
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/vis.c b/vis.c
index 612e3b5..f64fa82 100644
--- a/vis.c
+++ b/vis.c
@@ -106,6 +106,7 @@ typedef struct {
CHARWISE = 1 << 1,
INCLUSIVE = 1 << 2,
EXCLUSIVE = 1 << 3,
+ IDEMPOTENT = 1 << 4,
} type;
int count;
} Movement;
@@ -250,8 +251,8 @@ static Movement moves[] = {
[MOVE_LINE_FINISH] = { .txt = text_line_finish, .type = LINEWISE },
[MOVE_LINE_END] = { .txt = text_line_end, .type = LINEWISE },
[MOVE_LINE_NEXT] = { .txt = text_line_next, .type = LINEWISE },
- [MOVE_LINE] = { .cmd = line, .type = LINEWISE },
- [MOVE_COLUMN] = { .cmd = column, .type = CHARWISE },
+ [MOVE_LINE] = { .cmd = line, .type = LINEWISE|IDEMPOTENT},
+ [MOVE_COLUMN] = { .cmd = column, .type = CHARWISE|IDEMPOTENT},
[MOVE_CHAR_PREV] = { .win = window_char_prev },
[MOVE_CHAR_NEXT] = { .win = window_char_next },
[MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE },
@@ -562,10 +563,9 @@ static size_t till_left(const Arg *arg) {
}
static size_t line(const Arg *arg) {
- if (action.count == 1)
+ if (action.count == 0)
return text_size(vis->win->text);
size_t pos = text_pos_by_lineno(vis->win->text, action.count);
- action.count = 0;
return pos;
}
@@ -574,9 +574,9 @@ static size_t column(const Arg *arg) {
EditorWin *win = vis->win;
size_t pos = window_cursor_get(win->win);
Iterator it = text_iterator_get(win->text, text_line_begin(win->text, pos));
- while (action.count-- > 0 && text_iterator_byte_get(&it, &c) && c != '\n')
+ int count = action.count;
+ while (count > 0 && text_iterator_byte_get(&it, &c) && c != '\n')
text_iterator_byte_next(&it, NULL);
- action.count = 0;
return it.pos;
}
@@ -875,8 +875,7 @@ static void action_do(Action *a) {
Text *txt = vis->win->text;
Win *win = vis->win->win;
size_t pos = window_cursor_get(win);
- if (a->count == 0)
- a->count = 1;
+ int count = MAX(1, a->count);
OperatorContext c = {
.count = a->count,
.pos = pos,
@@ -886,14 +885,14 @@ static void action_do(Action *a) {
if (a->movement) {
size_t start = pos;
- for (int i = 0; i < a->count; i++) {
+ for (int i = 0; i < count; i++) {
if (a->movement->txt)
pos = a->movement->txt(txt, pos);
else if (a->movement->win)
pos = a->movement->win(win);
else
pos = a->movement->cmd(&a->arg);
- if (pos == EPOS)
+ if (pos == EPOS || a->movement->type & IDEMPOTENT)
break;
}
@@ -918,7 +917,7 @@ static void action_do(Action *a) {
} else if (a->textobj) {
Filerange r;
c.range.start = c.range.end = pos;
- for (int i = 0; i < a->count; i++) {
+ for (int i = 0; i < count; i++) {
r = a->textobj->range(txt, pos);
if (!text_range_valid(&r))
break;
@@ -929,7 +928,7 @@ static void action_do(Action *a) {
c.range = text_range_union(&c.range, &r);
- if (i < a->count - 1) {
+ if (i < count - 1) {
if (a->textobj == &textobjs[TEXT_OBJ_LINE_UP]) {
pos = c.range.start - 1;
} else {