summaryrefslogtreecommitdiff
path: root/txt.h
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 00:22:17 -0500
committerWormHeamer2026-01-02 00:22:17 -0500
commit8fa897bdfdfef633e669cd980d856ea05ef83022 (patch)
treed20162d8fe8cf8343a53cb63c5ead463c7f4033c /txt.h
parentcff961a844962fcd61ee04bbe67777d442d0c76f (diff)
undo/redo
Diffstat (limited to 'txt.h')
-rw-r--r--txt.h27
1 files changed, 21 insertions, 6 deletions
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);