commit 4028cd41c96a55da45f854eecc1e845676b15fe4
parent 489bea96be834958de96769e6b6e4a9324264696
Author: ssnf <ssnf@ssnf.xyz>
Date: Tue, 1 Feb 2022 23:38:04 +0000
Improved fr_update()
Diffstat:
M | sim.c | | | 54 | ++++++++++++++++++++++++++++-------------------------- |
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git a/sim.c b/sim.c
@@ -104,7 +104,7 @@ static void fr_close(Frame* fr);
static void fr_init(Frame* fr);
static void fr_insert(Frame* p, Frame* q, ushort n);
static void fr_insure(Frame* fr, ushort n);
-static void fr_update();
+static void fr_update(int arg);
static void fr_zero(Frame*);
static void paste(int arg);
static void search(int arg);
@@ -276,7 +276,7 @@ change(int arg)
buf->c[f->i] = Change;
buf->arg[f->i] = arg;
buf->count[f->i] = count;
- fr_update();
+ fr_update(1);
}
static void
@@ -323,7 +323,7 @@ delete(int arg)
if (f->dot.p0 == f->s->n && f->dot.p0)
--f->dot.p0;
f->dot.p1 = f->dot.p0;
- fr_update();
+ fr_update(1);
}
static void
@@ -363,7 +363,7 @@ dot(int arg)
f->dot.p1 = f->dot.p0;
break;
}
- fr_update();
+ fr_update(1);
}
static void
@@ -377,7 +377,7 @@ redo(int arg)
str_insert(f->s, &buf->is[f->i], buf->p0[f->i]);
f->dot.p0 = f->dot.p1 = buf->p0[f->i];
f->dirty = '*';
- fr_update();
+ fr_update(1);
}
static void
@@ -426,6 +426,7 @@ isword(uchar c)
case ',': case '<': case '>': case '#':
case '*': case '+': case '-': case '!':
case '%': case '\\': case '/': case '"':
+ case '=':
return 0;
}
return 1;
@@ -457,7 +458,7 @@ insert(int arg)
}
for (;;) {
win_query(&w);
- fr_update();
+ fr_update(1);
switch ((c.s[0] = fgetc(stdin))) {
case Esc:
goto endmode;
@@ -622,7 +623,7 @@ fr_insure(Frame* fr, ushort n)
}
static void
-fr_update()
+fr_update(int arg)
{
Frame fr0;
Posn p0, p1;
@@ -634,12 +635,19 @@ fr_update()
printf(ED);
goto status;
}
- if (1 || !fr->n || f->dot.p0 != f->dot.p1 || f->dot.p1 > fr->a[fr->n - 1].p1 || f->dot.p1 < fr->a[0].p0 || fr->n - fr->dot <= w.wy || fr->dot <= half) {
+ if (arg || !fr->n || f->dot.p1 < fr->a[fr->dot].p0
+ || f->dot.p1 > fr->a[fr->n ? fr->n - 1 : 0].p1
+ || (((fr->dot < half && fr->a[0].p0 && (fr->n > w.wy * 3))
+ || (fr->dot + half + 1 > fr->n))
+ && (fr->a[fr->n ? fr->n - 1 : 0].p1 != f->s->n)
+ )
+ ) {
fr_zero(fr);
for (p0 = f->dot.p1; p0; --p0)
if (f->s->s[p0 - 1] == '\n')
break;
- if ((p1 = p0)) {
+ p1 = p0;
+ if (p1) {
fr_init(&fr0);
for (--p1; p1 && fr->n < w.wy;) {
for (;p1 && f->s->s[p1 - 1] != '\n'; --p1);
@@ -651,18 +659,15 @@ fr_update()
}
fr_close(&fr0);
}
- for (p1 = p0; p1 < f->s->n && fr->n < 3 * w.wy;) {
+ for (p1 = p0; p1 < f->s->n && fr->n < w.wy * 3;) {
blind_reader(fr, f->s, p1);
p1 = fr->a[fr->n - 1].p1 + 1;
}
- for (;f->dot.p1 > fr->a[fr->dot].p1; ++fr->dot);
- goto full_update;
- }
- if (f->dot.p1 > fr->a[fr->dot].p1 || f->dot.p1 < fr->a[fr->dot].p0) {
- for (;f->dot.p1 > fr->a[fr->dot].p1; ++fr->dot);
- for (;f->dot.p1 < fr->a[fr->dot].p0; --fr->dot);
- goto full_update;
}
+ for (;f->dot.p1 < fr->a[fr->dot].p0 && fr->dot; --fr->dot);
+ for (;f->dot.p1 > fr->a[fr->dot].p1; ++fr->dot);
+ printf(ED);
+ blind_writer(f->s, fr, half, fr->dot, half, half + (w.wy % 2));
status:
printf(CSI "%uH", w.wy);
printf(STATUS);
@@ -673,10 +678,6 @@ fr_update()
}
printf(CSI "%u;%luH", half, p1);
return;
- full_update:
- printf(ED);
- blind_writer(f->s, fr, half, fr->dot, half, half + (w.wy % 2));
- goto status;
}
static void
@@ -805,8 +806,8 @@ search(int arg)
return;
}
} else {
+ pos = f->dot.p1;
for (;;) {
- pos = f->dot.p1;
for (;move(Left), f->dot.p1 && f->s->s[f->dot.p1] != srch.s[0];);
if (!strncmp(f->s->s + f->dot.p1, srch.s, srch.n))
break;
@@ -815,11 +816,12 @@ search(int arg)
return;
}
}
- if (srch.s[0] == '\n' && srch.s[1] != '\n')
- move(Right);
p = f->s->s + f->dot.p1;
}
f->dot.p0 = f->dot.p1 = p - f->s->s;
+ if (srch.s[0] == '\n' && srch.s[1] != '\n')
+ move(Right);
+ fr_update(1);
}
static int
@@ -968,7 +970,7 @@ undo(int arg)
str_insert(f->s, &buf->ds[f->i], buf->p0[f->i]);
f->dot.p0 = f->dot.p1 = buf->p0[f->i--];
f->dirty = '*';
- fr_update();
+ fr_update(1);
}
static void
@@ -1006,7 +1008,7 @@ main(int argc, char* argv[])
}
for (;;) {
win_query(&w);
- fr_update();
+ fr_update(0);
c = fgetc(stdin);
for (i = 0; i < LENGTH(keys); ++i) {
if (keys[i].key == c) {