From db8eea8baf396a965cc0c07ea8649dead043747f Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sat, 3 Jan 2026 06:01:46 -0500 Subject: hopefully squash the history corruption bug once and for all --- txt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/txt.c b/txt.c index 45e6af4..07bd0bd 100644 --- a/txt.c +++ b/txt.c @@ -278,20 +278,22 @@ void txt_hist_push(Txt *t, TxtLoc cur) { return; } if (t->hist.i + 1 < t->hist.n) t->hist.n = t->hist.i + 1; - if (t->hist.n == TXT_HIST_MAX) { - /* TODO: this is maybe still buggy? */ + if (t->hist.n) t->hist.i++; + if (t->hist.i == TXT_HIST_MAX) { free(t->hist.v[0].v); MOVE(&t->hist.v[0], &t->hist.v[1], TXT_HIST_MAX - 1); + MOVE(&t->hist.cur[0], &t->hist.cur[1], TXT_HIST_MAX - 1); + memset(&t->hist.v[TXT_HIST_MAX - 1], 0, sizeof(*t->hist.v)); t->hist.i--; t->hist.n--; } - if (t->hist.i + 1 == t->hist.n) t->hist.i++; DA_FIT(&t->hist.v[t->hist.i], t->ptbl.n); memcpy(t->hist.v[t->hist.i].v, t->ptbl.v, sizeof(TxtPiece) * t->ptbl.n); t->hist.v[t->hist.i].n = t->ptbl.n; t->hist.v[t->hist.i].dirty = t->ptbl.dirty; t->hist.cur[t->hist.i] = cur; t->hist.n++; + ASSERT(t->hist.n == t->hist.i + 1); } int txt_hist_set(Txt *t, TxtLoc *cur) { -- cgit v1.2.3