diff options
| author | WormHeamer | 2025-12-29 01:24:15 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-12-29 01:24:15 -0500 |
| commit | e40c14f15bc8607717bd1955dc8df5180f36c90b (patch) | |
| tree | 07444ace9a06a78d8002689a931f68601ba86a7b /main.c | |
| parent | 01ed23855e2c53b7286a58d960592a21edaaa086 (diff) | |
next_word(), prev_word()
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -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++; |
