From 782b3a4ecd5ff125b477a6486d62761fa6cfcd9f Mon Sep 17 00:00:00 2001 From: ikozyris <80053394+ikozyris@users.noreply.github.com> Date: Sun, 27 Oct 2024 10:38:06 +0200 Subject: [PATCH] fix: move to mid of tab now the cursor is moved to the end of tab --- main.cpp | 12 ++++++------ utils/sizes.c | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 2307ae0..c86bdce 100755 --- a/main.cpp +++ b/main.cpp @@ -97,11 +97,11 @@ int main(int argc, char *argv[]) ++it; wrap.clear(); ofx = 0; // invalidated - if (y == (maxy - 1) && ry < curnum) + if (y == maxy - 1 && ry < curnum) scrolldown(); else { - wmove(text_win, y + 1, x); - ofx = calc_offset_dis(x, 0, *it); + ofx = calc_offset_dis(x, *it); + wmove(text_win, y + 1, x = rx); } break; @@ -112,9 +112,9 @@ int main(int argc, char *argv[]) } if (y == 0 && ofy != 0) scrollup(); else if (y != 0) { - wmove(text_win, y - 1, x); - --it; - ofx = calc_offset_dis(x, 0, *it); + --it; + ofx = calc_offset_dis(x, *it); + wmove(text_win, y - 1, x = rx); } wrap.clear(); break; diff --git a/utils/sizes.c b/utils/sizes.c index 70e6b97..03e03c4 100644 --- a/utils/sizes.c +++ b/utils/sizes.c @@ -42,13 +42,15 @@ inline void get_off(unsigned &x, unsigned &i, const gap_buf &buf) i++; } -// offset until displayed x from from bytes in buf -long calc_offset_dis(unsigned dx, unsigned from, const gap_buf &buf) +// returns offset until displayed x from from bytes in buf (bytes - dx) +// global rx becomes the dx where counting stopped at +long calc_offset_dis(unsigned dx, const gap_buf &buf) { - unsigned x = 0, i = from; + unsigned x = 0, i = 0; while (x < dx && i < buf.len) get_off(x, i, buf); - return (long)i - (long)from - (long)x; + rx = x; + return (long)i - (long)x; } // displayed characters dx to bytes