From bafc45b028ad8db3d8be51cf1a09b7f118d75503 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 15 Sep 2023 08:52:39 -0700 Subject: [PATCH] bugfix: crash when using mouse wheel All the Text functions assume the cursor is always on a text line. I was violating that invariant. * When scrolling up, I start the cursor at the top-most line below the screen top. * When scrolling down, I start the cursor at the top-most line below the screen bottom. I think it would feel slightly more natural for it to be the bottom-most line above the screen bottom. However, the Text functions maintain an invariant that the bottom-most line in a buffer will be text. There's no such invariant for the top-most line. --- edit.lua | 2 ++ source_edit.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/edit.lua b/edit.lua index 1ac2bd1..d30dbdc 100644 --- a/edit.lua +++ b/edit.lua @@ -343,11 +343,13 @@ end function edit.mouse_wheel_move(State, dx,dy) if dy > 0 then State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos} + edit.put_cursor_on_next_text_line(State) for i=1,math.floor(dy) do Text.up(State) end elseif dy < 0 then State.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos} + edit.put_cursor_on_next_text_line(State) for i=1,math.floor(-dy) do Text.down(State) end diff --git a/source_edit.lua b/source_edit.lua index f949aa5..6dbf883 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -333,11 +333,13 @@ end function edit.mouse_wheel_move(State, dx,dy) if dy > 0 then State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos} + edit.put_cursor_on_next_text_line(State) for i=1,math.floor(dy) do Text.up(State) end elseif dy < 0 then State.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos} + edit.put_cursor_on_next_text_line(State) for i=1,math.floor(-dy) do Text.down(State) end -- 2.11.4.GIT