From d16f78195865c200481123caaa91e52152ffdc41 Mon Sep 17 00:00:00 2001 From: wrmr Date: Sun, 3 Nov 2024 13:32:33 -0500 Subject: move messy internal line navigation logic into doc.c --- nav.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'nav.c') 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) { -- cgit 1.4.1-2-gfad0