summary refs log tree commit diff
path: root/nav.c
diff options
context:
space:
mode:
authorwrmr2024-11-03 13:32:33 -0500
committerwrmr2024-11-03 13:32:33 -0500
commitd16f78195865c200481123caaa91e52152ffdc41 (patch)
tree4ca9ae1c487f19807018ddf113f1baf608d445c5 /nav.c
parent332db163a4524552b583776bd3ff172b8eadbf5c (diff)
move messy internal line navigation logic into doc.c
Diffstat (limited to 'nav.c')
-rw-r--r--nav.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/nav.c b/nav.c
index 8df829e..6d81ddd 100644
--- a/nav.c
+++ b/nav.c
@@ -51,26 +51,15 @@ size_t pg_lines(void) {
 }
 
 struct doc_line *nav_cur_line(struct nav_state *ns) {
-	return (struct doc_line *)&ns->histv[ns->cur_doc].txt.buf[ns->cur_ofs[ns->cur_doc]];
+	return doc_line_at(&ns->histv[ns->cur_doc], ns->cur_ofs[ns->cur_doc]);
 }
 
 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 + sizeof(struct doc_line); 
-		return 1;
-	} else {
-		return 0;
-	}
+	return !doc_line_prev(&ns->histv[ns->cur_doc], &ns->cur_ofs[ns->cur_doc]);
 }
 
 int nav_line_down(struct nav_state *ns) {
-	struct doc_line *l = nav_cur_line(ns);
-	if (ns->cur_ofs[ns->cur_doc] + sizeof(struct doc_line) + l->len < ns->histv[ns->cur_doc].txt.sz) {
-		ns->cur_ofs[ns->cur_doc] += l->len + sizeof(struct doc_line); 
-		return 1;
-	} else {
-		return 0;
-	}
+	return !doc_line_next(&ns->histv[ns->cur_doc], &ns->cur_ofs[ns->cur_doc]);
 }
 
 void nav_pg_up(struct nav_state *ns) {