summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-03 06:01:46 -0500
committerWormHeamer2026-01-03 06:01:46 -0500
commitdb8eea8baf396a965cc0c07ea8649dead043747f (patch)
tree6aea84547864dad87bb1ea3f5f3c05ae3664ba4a
parentf34794f3e298bd5014ad6329d5bc8f015db042aa (diff)
hopefully squash the history corruption bug once and for all
-rw-r--r--txt.c8
1 files 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) {