From 907257879c4b1bffb7acfd242d63ac2b984fbebd Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Thu, 19 Mar 2026 16:22:13 -0500 Subject: [PATCH] Fixed EditBox causing crash if parent container is scrolled and EditBox is clicked --- lib/cyberarm_engine/ui/elements/edit_box.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/cyberarm_engine/ui/elements/edit_box.rb b/lib/cyberarm_engine/ui/elements/edit_box.rb index 390d45e..69780bb 100644 --- a/lib/cyberarm_engine/ui/elements/edit_box.rb +++ b/lib/cyberarm_engine/ui/elements/edit_box.rb @@ -79,7 +79,19 @@ module CyberarmEngine end def caret_position_under_mouse(mouse_x, mouse_y) - active_line = row_at(mouse_y) + # get y scroll offset of element to get EditBox's selected row + y_scroll_offset = 0 + e = parent + while (e) + if e.is_a?(Container) + y_scroll_offset += e.scroll_position.y + + # root element has no parent so loop will terminate + e = e.parent + end + end + + active_line = row_at(mouse_y - y_scroll_offset) right_offset = column_at(mouse_x, mouse_y) buffer = @text_input.text.lines[0..active_line].join if active_line != 0