diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-04-11 10:39:46 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-04-11 10:43:23 +0200 |
| commit | 3ea63f3951dd8e1c624966d6966ea8ca0e359b09 (patch) | |
| tree | fc90659e0dfed41a9419edd233dde54751a38471 | |
| parent | 3f3125ee103401cf561b38b00f9b34187b8d6a52 (diff) | |
| download | vis-3ea63f3951dd8e1c624966d6966ea8ca0e359b09.tar.gz vis-3ea63f3951dd8e1c624966d6966ea8ca0e359b09.tar.xz | |
Eliminate global state for repetition of last modification
| -rw-r--r-- | config.def.h | 8 | ||||
| -rw-r--r-- | editor.c | 1 | ||||
| -rw-r--r-- | editor.h | 1 | ||||
| -rw-r--r-- | vis.c | 20 |
4 files changed, 16 insertions, 14 deletions
diff --git a/config.def.h b/config.def.h index aa079d7..4e7b5da 100644 --- a/config.def.h +++ b/config.def.h @@ -572,8 +572,8 @@ static void vis_mode_insert_input(const char *str, size_t len) { static size_t oldpos = EPOS; size_t pos = window_cursor_get(vis->win->win); if (pos != oldpos) - buffer_truncate(&buffer_repeat); - buffer_append(&buffer_repeat, str, len); + buffer_truncate(&vis->buffer_repeat); + buffer_append(&vis->buffer_repeat, str, len); oldpos = pos + len; action_reset(&action_prev); action_prev.op = &ops[OP_REPEAT_INSERT]; @@ -594,8 +594,8 @@ static void vis_mode_replace_input(const char *str, size_t len) { static size_t oldpos = EPOS; size_t pos = window_cursor_get(vis->win->win); if (pos != oldpos) - buffer_truncate(&buffer_repeat); - buffer_append(&buffer_repeat, str, len); + buffer_truncate(&vis->buffer_repeat); + buffer_append(&vis->buffer_repeat, str, len); oldpos = pos + len; action_reset(&action_prev); action_prev.op = &ops[OP_REPEAT_REPLACE]; @@ -411,6 +411,7 @@ void editor_free(Editor *ed) { ed->ui->free(ed->ui); map_free(ed->cmds); map_free(ed->options); + buffer_free(&ed->buffer_repeat); free(ed); } @@ -123,6 +123,7 @@ struct Editor { bool autoindent; /* whether indentation should be copied from previous line on newline */ Map *cmds; /* ":"-commands, used for unique prefix queries */ Map *options; /* ":set"-options */ + Buffer buffer_repeat; /* holds data to repeat last insertion/replacement */ }; Editor *editor_new(Ui*); @@ -157,7 +157,6 @@ static Mode *mode_prev; /* previsouly active user mode */ static Mode *mode_before_prompt; /* user mode which was active before entering prompt */ static Action action; /* current action which is in progress */ static Action action_prev; /* last operator action used by the repeat '.' key */ -static Buffer buffer_repeat;/* repeat last modification i.e. insertion/replacement */ /** operators */ static void op_change(OperatorContext *c); @@ -686,19 +685,20 @@ static void op_join(OperatorContext *c) { } static void op_repeat_insert(OperatorContext *c) { - if (!buffer_repeat.len) + size_t len = vis->buffer_repeat.len; + if (!len) return; - editor_insert(vis, c->pos, buffer_repeat.data, buffer_repeat.len); - window_cursor_to(vis->win->win, c->pos + buffer_repeat.len); + editor_insert(vis, c->pos, vis->buffer_repeat.data, len); + window_cursor_to(vis->win->win, c->pos + len); } static void op_repeat_replace(OperatorContext *c) { - if (!buffer_repeat.len) + size_t chars = 0, len = vis->buffer_repeat.len; + if (!len) return; - - size_t chars = 0; - for (size_t i = 0; i < buffer_repeat.len; i++) { - if (ISUTF8(buffer_repeat.data[i])) + const char *data = vis->buffer_repeat.data; + for (size_t i = 0; i < len; i++) { + if (ISUTF8(data[i])) chars++; } @@ -878,7 +878,7 @@ static void replace(const Arg *arg) { size_t pos = window_cursor_get(vis->win->win); action_reset(&action_prev); action_prev.op = &ops[OP_REPEAT_REPLACE]; - buffer_put(&buffer_repeat, k.str, strlen(k.str)); + buffer_put(&vis->buffer_repeat, k.str, strlen(k.str)); editor_delete_key(vis); editor_insert_key(vis, k.str, strlen(k.str)); text_snapshot(vis->win->text->data); |
