commit 9d4a59227d2c988f7aa21f674e93b530e62444c2
parent c69bd6a6e243c9d2f791800e836a07ac652579e6
Author: ssnf <ssnf@ssnf.xyz>
Date: Sat, 21 Aug 2021 19:57:38 +0000
improved delete()
Diffstat:
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -21,7 +21,7 @@ Key keys[] = {
{ 'o', insert , Down },
{ 'O', insert , Up },
{ 'd', delete },
- { 'x', delete , 1 },
+ { 'x', delete , 'x' },
{ 'E', file_open },
{ 'q', file_close, -1 },
{ 'S', file_save, -1 },
diff --git a/sim.c b/sim.c
@@ -203,23 +203,24 @@ delete(int arg)
if (!f->s->n)
return;
- if (arg == 1) {
- str_delete(f->s, f->dot.p0, f->dot.p1 + 1);
- if (f->dot.p1 == f->s->n)
- move(Left);
- f->dirty = '*';
- fr_update(1);
- return;
- }
- m = fr->a[fr->dot].p0;
- switch (fgetc(stdin)) {
+ if (!arg)
+ arg = fgetc(stdin);
+ switch (arg) {
+ case 'x':
+ m = f->dot.p0;
+ n = f->dot.p1 + 1;
+ if (f->dot.p1 == f->s->n)
+ move(Left);
+ break;
case 'd':
+ m = fr->a[fr->dot].p0;
n = fr->a[fr->dot].p1 + 1;
move(StartLine);
if (fr->dot == fr->n - 1)
move(Up);
break;
case 'G':
+ m = fr->a[fr->dot].p0;
n = f->s->n;
move(Up);
break;
@@ -228,6 +229,22 @@ delete(int arg)
n = fr->a[fr->dot].p1 + 1;
move(Top);
break;
+ case 'w':
+ m = f->dot.p0;
+ move(EndWord);
+ move(Right);
+ n = f->dot.p1;
+ f->dot.p0 = f->dot.p1 = m;
+ break;
+ case 't':
+ arg = fgetc(stdin);
+ if (arg == Esc)
+ return;
+ for (;f->dot.p1 < f->s->n && f->s->s[f->dot.p1] != arg; ++f->dot.p1);
+ m = f->dot.p0;
+ n = f->dot.p1;
+ f->dot.p0 = f->dot.p1 = m;
+ break;
default:
return;
}