From b3373a2182ce3907cf42b5b0a3952753a71790ec Mon Sep 17 00:00:00 2001 From: d0k3 Date: Wed, 26 Jul 2017 21:52:40 +0200 Subject: [PATCH] Fix text viewer line numbers --- source/godmode.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/godmode.c b/source/godmode.c index e440a23..9b85857 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -78,7 +78,7 @@ static inline char* LineSeek(const char* text, u32 len, u32 ww, const char* line char* lf = ((char*) line - 1); // ensure we are at the start of the line - while ((lf >= text) && (*lf != '\n')) lf--; + while ((lf > text) && (*lf != '\n')) lf--; // handle backwards search for (; (add < 0) && (lf >= text); add++) @@ -457,8 +457,13 @@ u32 FileTextViewer(const char* path) { // check for problems, apply changes if (!ww && (line0_next > llast_nww)) line0_next = llast_nww; else if (ww && (line0_next > llast_ww)) line0_next = llast_ww; - for (int i = (line0_next < line0) ? -1 : 1; line0 != line0_next; line0 += i) - if (*line0 == '\n') lcurr += i; // fix line number + if (line0_next < line0) { // fix line number for decrease + do if (*(--line0) == '\n') lcurr--; + while (line0 > line0_next); + } else { // fix line number for increase / same + for (; line0_next > line0; line0++) + if (*line0 == '\n') lcurr++; + } if (off_disp + llen_disp > llen_max) off_disp = llen_max - llen_disp; if ((off_disp < 0) || ww) off_disp = 0; }