Going to $ made draw_page render cursor to wrong line

---
  toys/pending/vi.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
From a2cce5c7cec24adfe403cc33a4738bd0e360d9ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jarno=20M=C3=A4kip=C3=A4=C3=A4?= <[email protected]>
Date: Thu, 6 Feb 2020 21:06:43 +0200
Subject: [PATCH] vi: fix pointer pos when at end of line

Going to $ made draw_page render cursor to wrong line
---
 toys/pending/vi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/toys/pending/vi.c b/toys/pending/vi.c
index 5086a0da..c6f44ef6 100644
--- a/toys/pending/vi.c
+++ b/toys/pending/vi.c
@@ -418,9 +418,9 @@ static int text_codepoint(char *dest, size_t offset)
 static size_t text_sol(size_t offset)
 {
   size_t pos;
-  if (!TT.filesize) return 0;
+  if (!TT.filesize || !offset) return 0;
   else if (TT.filesize <= offset) return TT.filesize-1;
-  else if ((pos = text_strrchr(offset, '\n')) == SIZE_MAX) return 0;
+  else if ((pos = text_strrchr(offset-1, '\n')) == SIZE_MAX) return 0;
   else if (pos < offset) return pos+1;
   return offset;
 }
-- 
2.19.1

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to