diff options
author | June McEnroe <june@causal.agency> | 2022-03-12 20:08:21 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-03-12 20:08:21 -0500 |
commit | f5a362cc8a6e187c33f45c502ffdddc183d311f5 (patch) | |
tree | 92d52f1a5dc0383d9e46fbbc049441a4dc68e7f6 | |
parent | Use a bool for vi.mode (diff) | |
download | catgirl-f5a362cc8a6e187c33f45c502ffdddc183d311f5.tar.gz catgirl-f5a362cc8a6e187c33f45c502ffdddc183d311f5.zip |
Implement $, 0, A, I, a
Diffstat (limited to '')
-rw-r--r-- | edit.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/edit.c b/edit.c index 67c35b9..15188a6 100644 --- a/edit.c +++ b/edit.c @@ -256,12 +256,17 @@ static int viCommand(struct Edit *e, wchar_t ch) { e->vi.count += ch - L'0'; return 0; } + e->vi.verb = ch; switch (ch) { break; case Esc: viEscape(e); + break; case L'$': if (e->len) e->pos = e->len - 1; viEscape(e); break; case L'0': e->pos = 0; viEscape(e); - break; case L'R': e->vi.verb = 'R'; e->vi.mode = Insert; - break; case L'i': e->vi.verb = 'i'; e->vi.mode = Insert; - break; case L'r': e->vi.verb = 'r'; e->vi.mode = Insert; + break; case L'A': e->pos = e->len; e->vi.mode = Insert; + break; case L'I': e->pos = 0; e->vi.mode = Insert; + break; case L'R': e->vi.mode = Insert; + break; case L'a': if (e->len) e->pos++; e->vi.mode = Insert; + break; case L'i': e->vi.mode = Insert; + break; case L'r': e->vi.mode = Insert; } return 0; } @@ -393,6 +398,17 @@ int main(void) { editVi(&e, Esc); assert(eq(&e, "fo\0bo")); + fix(&e, "foo"); + vi(&e, "\33I"); + assert(e.vi.mode == Insert); + assert(eq(&e, "\0foo")); + vi(&e, "\33A"); + assert(e.vi.mode == Insert); + assert(eq(&e, "foo\0")); + vi(&e, "\33a"); + assert(e.vi.mode == Insert); + assert(eq(&e, "foo\0")); + fix(&e, "foo bar"); editVi(&e, Erase); assert(eq(&e, "foo ba\0")); @@ -417,6 +433,12 @@ int main(void) { assert(eq(&e, "y\0yo")); vi(&e, "3rz"); assert(eq(&e, "yz\0z")); + + fix(&e, "foo bar"); + vi(&e, "\0330"); + assert(eq(&e, "\0foo bar")); + vi(&e, "$"); + assert(eq(&e, "foo ba\0r")); } #endif /* TEST */ |