From 8fa897bdfdfef633e669cd980d856ea05ef83022 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Fri, 2 Jan 2026 00:22:17 -0500 Subject: undo/redo --- txt.h | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'txt.h') diff --git a/txt.h b/txt.h index 5df33a7..148369e 100644 --- a/txt.h +++ b/txt.h @@ -5,6 +5,8 @@ #include "arena.h" #include "str.h" +#define TXT_HIST_MAX 32 + typedef enum : u8 { TXT_SRC, TXT_ADD @@ -20,18 +22,27 @@ typedef struct { u32 n, c; } TxtBuf; +typedef DYNARR(TxtPiece) TxtPieceTbl; + +typedef struct { + struct Txt *t; + u32 p, i; +} TxtLoc; + typedef struct { - DYNARR(TxtPiece) ptbl; + TxtPieceTbl v[TXT_HIST_MAX]; + TxtLoc cur[TXT_HIST_MAX]; + u32 i, n; +} TxtHist; + +typedef struct Txt { + TxtPieceTbl ptbl; + TxtHist hist; TxtBuf buf[2]; u32 len; int dirty; } Txt; -typedef struct { - Txt *t; - u32 p, i; -} TxtLoc; - /* text buffer manipulation */ TxtLoc txt_split_piece(TxtLoc l); @@ -43,6 +54,10 @@ int txt_load(Txt *b, const char *path); int txt_save(Txt *b, const char *path); void txt_free(Txt *b); +void txt_hist_push(Txt *t, TxtLoc cur); +int txt_hist_fwd(Txt *t, TxtLoc *cur); +int txt_hist_back(Txt *t, TxtLoc *cur); + Str txt_collect_range(TxtLoc lo, TxtLoc hi, Arena *a); u32 txt_read_chunk(TxtLoc *lo, TxtLoc hi, char *buf, u32 sz); Str txt_next_chunk(TxtLoc *l); -- cgit v1.2.3