sim

the sim text editor
git clone git://ssnf.xyz/sim
Log | Files | Refs | README

commit 8e29881a071c05910d1cd7a0cb1b955be0c9d58e
parent bb591e0b48c7aecae71d474faae6e69a764e112d
Author: ssnf <ssnf@ssnf.xyz>
Date:   Tue, 28 Jan 2025 19:44:50 +0000

fix dot() and improve buffer handling

Diffstat:
Msim.c | 43++++++++++++++++++++-----------------------
1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/sim.c b/sim.c @@ -86,8 +86,7 @@ void* erealloc(void*, ulong); static void blind_reader(Frame* fr, Posn p0); static void blind_writer(ushort line, ushort offset, ushort top, ushort bot); static void buf_add( - Buffer* b, String* is, String* ds, - uint c, uint arg, uint count, Posn p0 + String* is, String* ds, uint c, uint arg, uint count ); static void change(int arg); static uint charsiz(char c, ulong wx); @@ -233,21 +232,19 @@ blind_writer(ushort line, ushort offset, ushort top, ushort bot) } static void -buf_add( - Buffer* b, String* is, String* ds, - uint c, uint arg, uint count, Posn p0 -) { - b->n = ++f->i + 1; - str_zero(&b->is[f->i]); - str_zero(&b->ds[f->i]); +buf_add(String* is, String* ds, uint c, uint arg, uint count) +{ + buf->n = ++f->i + 1; + str_zero(&buf->is[f->i]); + str_zero(&buf->ds[f->i]); if (is != NULL) - str_insert(&b->is[f->i], is, 0); + str_insert(&buf->is[f->i], is, 0); if (ds != NULL) - str_insert(&b->ds[f->i], ds, 0); - b->c[f->i] = c; - b->arg[f->i] = arg; - b->count[f->i] = count; - b->p0[f->i] = p0; + str_insert(&buf->ds[f->i], ds, 0); + buf->c[f->i] = c; + buf->arg[f->i] = arg; + buf->count[f->i] = count; + buf->p0[f->i] = f->dot.p0; fr_zero(fr); } @@ -344,7 +341,7 @@ delete(int arg) str_zero(&istr); str_adds(&s, f->s.s + f->dot.p0, f->dot.p1 + 1 - f->dot.p0); str_adds(&istr, f->s.s + f->dot.p0, f->dot.p1 + 1 - f->dot.p0); - buf_add(buf, NULL, &s, Delete, arg, count, f->dot.p0); + buf_add(NULL, &s, Delete, arg, count); str_delete(&f->s, f->dot.p0, f->dot.p1 + 1); str_close(&s); if (f->dot.p0 == f->s.n && f->dot.p0) @@ -359,7 +356,7 @@ dot(int arg) String ds; if (f->i < 0) - f->i = 0; + return; arg = buf->arg[f->i]; counter = buf->count[f->i]; switch (buf->c[f->i]) { @@ -368,8 +365,8 @@ dot(int arg) move(EndLine); else move(arg); - str_insert(&f->s, &istr, f->dot.p0); - buf_add(buf, &istr, NULL, Insert, arg, counter, f->dot.p0); + str_insert(&f->s, &buf->is[f->i], f->dot.p0); + buf_add(&buf->is[f->i], NULL, Insert, arg, counter); break; case Delete: delete(arg); @@ -388,8 +385,7 @@ dot(int arg) if (buf->is[f->i].n) str_insert(&f->s, &buf->is[f->i], f->dot.p0); buf_add( - buf, &buf->is[f->i], &ds, Change, arg, - buf->count[f->i], f->dot.p0 + &buf->is[f->i], &ds, Change, arg, buf->count[f->i] ); str_close(&ds); f->dot.p1 = f->dot.p0; @@ -514,7 +510,7 @@ insert(int arg) str_insert(&istr, &s, istr.n); str_insert(&f->s, &s, f->dot.p0); } - buf_add(buf, &istr, NULL, Insert, arg, counter, f->dot.p0); + buf_add(&istr, NULL, Insert, arg, counter); str_close(&s), str_close(&c); f->dot.p0 = f->dot.p1; if (f->dot.p1 >= f->s.n) @@ -554,6 +550,7 @@ file_close(int arg) str_close(&f->s); str_close(&f->name); file_init(f); + buffer[f - file].n = 0; } static void @@ -860,7 +857,7 @@ static void paste(int arg) { str_insert(&f->s, &istr, f->dot.p0); - buf_add(buf, &istr, NULL, Insert, 0, 1, f->dot.p0); + buf_add(&istr, NULL, Insert, 0, 1); } static void