From e40c14f15bc8607717bd1955dc8df5180f36c90b Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Mon, 29 Dec 2025 01:24:15 -0500 Subject: next_word(), prev_word() --- main.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 17ab1bb..b0ba567 100644 --- a/main.c +++ b/main.c @@ -25,12 +25,17 @@ u32 cur = 0; int mode = 0; u32 count = 0; -int is_space(u32 c) { +static inline int is_space(u32 c) { return c <= 0x20 && c != 0; } -u32 move_word_back(Txt *t, u32 cur) { - TxtLoc l = txt_at(t, cur); +TxtLoc next_word(TxtLoc l) { + while (!at_end(l) && is_space(txt_chr(l))) l = cnext(l); + while (!at_end(l) && !is_space(txt_chr(l))) l = cnext(l); + return l; +} + +TxtLoc prev_word(TxtLoc l) { while (!at_start(l)) { TxtLoc n = bprev(l); if (!is_space(txt_chr(n))) break; @@ -41,14 +46,15 @@ u32 move_word_back(Txt *t, u32 cur) { if (is_space(txt_chr(n))) break; l = n; } - return txt_ofs(l); + return l; +} + +u32 move_word_back(Txt *t, u32 cur) { + return txt_ofs(prev_word(txt_at(t, cur))); } u32 move_word_fwd(Txt *t, u32 cur) { - TxtLoc l = txt_at(t, cur); - while (!at_end(l) && is_space(txt_chr(l))) l = cnext(l); - while (!at_end(l) && !is_space(txt_chr(l))) l = cnext(l); - return txt_ofs(l); + return txt_ofs(next_word(txt_at(t, cur))); } u32 move_char_back(Txt *t, u32 cur) { @@ -188,7 +194,8 @@ void find_view_window(Txt *t, u32 curs, TxtLoc *start, TxtLoc *end) { void draw(void *ctx) { (void)ctx; vui_clear(); - int x = 0, y = 0; + int lmarg = 0; + int x = lmarg, y = 0; TxtLoc start, end; find_view_window(&txt, cur, &start, &end); @@ -208,7 +215,7 @@ void draw(void *ctx) { } u32 c = txt_chr_next(&start); if (c == '\n') { - x = 0; + x = lmarg; y++; } else if (c == '\t') { x++; -- cgit v1.2.3