From d091dcad183c4cfa7a89a450afc0512085f08815 Mon Sep 17 00:00:00 2001 From: mcplayer3 <219271061+mcplayer3@users.noreply.github.com> Date: Mon, 8 Jun 2026 18:01:33 +1000 Subject: [PATCH] bedit: Prevented cursor moving past end of line --- halyde/apps/bedit.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/halyde/apps/bedit.lua b/halyde/apps/bedit.lua index 3fca4b3..b249de9 100644 --- a/halyde/apps/bedit.lua +++ b/halyde/apps/bedit.lua @@ -113,6 +113,9 @@ while true do end cursorY = cursorY - 1 -- The cursor absolute position still has to be moved, even if on-screen it won't move + if cursorX > string.len(lines[cursorY]) then -- cursor snapping + cursorX = string.len(lines[cursorY]) + end end if keyboard.keys[eventArgs[4]] == "down" then if cursorY - scrollY >= resY - 1 then @@ -125,6 +128,9 @@ while true do end end cursorY = cursorY + 1 + if cursorX > string.len(lines[cursorY]) then -- cursor snapping + cursorX = string.len(lines[cursorY]) + end end if keyboard.keys[eventArgs[4]] == "left" and cursorX > 1 then if cursorX - scrollX <= 1 then @@ -138,7 +144,7 @@ while true do end cursorX = cursorX - 1 end - if keyboard.keys[eventArgs[4]] == "right" then + if keyboard.keys[eventArgs[4]] == "right" and cursorX < string.len(lines[cursorY]) then -- TODO: make scrolling up and down lines that are shorter than cursorX snap to the end of the line if cursorX - scrollX >= resX then renderBufferFlag = true scrollX = scrollX + 1