summary refs log tree commit diff
diff options
context:
space:
mode:
authorwrmr2024-11-03 12:59:39 -0500
committerwrmr2024-11-03 12:59:39 -0500
commite5f222ed0020b0da3d1d6cf43d066d3deb0538b8 (patch)
tree874207332211ca7a0096efc5ba74415a0af440db
parent9faead33740e7b5b847478518fd3a270a2aa5c2a (diff)
make doc_line prev and next work more similarly
-rw-r--r--doc.c7
-rw-r--r--nav.c2
2 files changed, 4 insertions, 5 deletions
diff --git a/doc.c b/doc.c
index 658315c..d5da6bf 100644
--- a/doc.c
+++ b/doc.c
@@ -23,15 +23,14 @@ void doc_fini(struct doc *d) {
 }
 
 void doc_new_line(struct doc *d) {
-	size_t here = d->latest, there = d->txt.sz;
 	buf_grow(&d->txt, sizeof(struct doc_line));
-	*(struct doc_line *)&d->txt.buf[there] = (struct doc_line) {
-		.prev = there - here,
+	*(struct doc_line *)&d->txt.buf[d->txt.sz] = (struct doc_line) {
+		.prev = ((struct doc_line *)&d->txt.buf[d->latest])->len,
 		.link = DOC_LINK_NONE,
 		.len = 0
 	};
+	d->latest = d->txt.sz;
 	d->txt.sz += sizeof(struct doc_line);
-	d->latest = there;
 }
 
 void doc_add_line(struct doc *d, const char *s) {
diff --git a/nav.c b/nav.c
index 8f1d699..8df829e 100644
--- a/nav.c
+++ b/nav.c
@@ -56,7 +56,7 @@ struct doc_line *nav_cur_line(struct nav_state *ns) {
 
 int nav_line_up(struct nav_state *ns) {
 	if (ns->cur_ofs[ns->cur_doc] > 0) {
-		ns->cur_ofs[ns->cur_doc] -= nav_cur_line(ns)->prev; 
+		ns->cur_ofs[ns->cur_doc] -= nav_cur_line(ns)->prev + sizeof(struct doc_line); 
 		return 1;
 	} else {
 		return 0;