summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--txt.c10
-rw-r--r--txt.h9
2 files changed, 10 insertions, 9 deletions
diff --git a/txt.c b/txt.c
index b3074aa..38f34c4 100644
--- a/txt.c
+++ b/txt.c
@@ -215,11 +215,11 @@ u32 txt_chr(Txt *t, TxtLoc l) {
TxtLoc txt_at(Txt *b, u32 cur) {
for (u32 i = 0; i < b->ptbl.n; i++) {
if (cur < b->ptbl.v[i].n) {
- return (TxtLoc) { i, cur };
+ return (TxtLoc) { b, i, cur };
}
cur -= b->ptbl.v[i].n;
}
- return (TxtLoc) { b->ptbl.n - 1, b->ptbl.v[b->ptbl.n - 1].n };
+ return (TxtLoc) { b, b->ptbl.n - 1, b->ptbl.v[b->ptbl.n - 1].n };
}
u32 txt_ofs(Txt *b, TxtLoc l) {
@@ -244,11 +244,11 @@ TxtLoc txt_next(Txt *b, TxtLoc l) {
TxtLoc txt_prev(Txt *b, TxtLoc l) {
if (l.i > 0) {
- return (TxtLoc) { l.p, l.i - 1 };
+ return (TxtLoc) { b, l.p, l.i - 1 };
} else if (l.p > 0) {
- return (TxtLoc) { l.p - 1, b->ptbl.v[l.p - 1].n - 1 };
+ return (TxtLoc) { b, l.p - 1, b->ptbl.v[l.p - 1].n - 1 };
} else {
- return (TxtLoc) { 0, 0 };
+ return (TxtLoc) { b, 0, 0 };
}
}
diff --git a/txt.h b/txt.h
index ccc71be..3af9970 100644
--- a/txt.h
+++ b/txt.h
@@ -19,15 +19,16 @@ typedef struct {
} TxtBuf;
typedef struct {
- u32 p, i;
-} TxtLoc;
-
-typedef struct {
DYNARR(TxtPiece) ptbl;
TxtBuf buf[2];
u32 len;
} Txt;
+typedef struct {
+ Txt *t;
+ u32 p, i;
+} TxtLoc;
+
u32 txt_split_piece(Txt *b, u32 pi, u32 i);
void txt_remove_piece(Txt *b, u32 pi);
void txt_insert_piece(Txt *b, u32 pi, TxtBufIdx buf, u32 ofs, u32 n);