From c9cf5ecca83505ad1694b3c92f5ad8cdc03c8c8e Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 21 Nov 2022 17:51:04 -0800 Subject: [PATCH] we kept editfield as MOUSE_L for click and drag --- library/lua/gui/widgets.lua | 2 +- test/library/gui/widgets.EditField.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 84b625d52..e8093345f 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -334,7 +334,7 @@ function EditField:onInput(keys) elseif keys._MOUSE_L then local mouse_x, mouse_y = self:getMousePos() if mouse_x then - self:setCursor(self.start_pos + mouse_x - self.text_offset) + self:setCursor(self.start_pos + mouse_x - (self.text_offset or 0)) return true end elseif keys._STRING then diff --git a/test/library/gui/widgets.EditField.lua b/test/library/gui/widgets.EditField.lua index ba98f6dee..23558987b 100644 --- a/test/library/gui/widgets.EditField.lua +++ b/test/library/gui/widgets.EditField.lua @@ -40,17 +40,17 @@ function test.editfield_click() expect.eq(5, e.cursor) mock.patch(e, 'getMousePos', mock.func(0), function() - e:onInput{_MOUSE_L_DOWN=true} + e:onInput{_MOUSE_L=true} expect.eq(1, e.cursor) end) mock.patch(e, 'getMousePos', mock.func(20), function() - e:onInput{_MOUSE_L_DOWN=true} + e:onInput{_MOUSE_L=true} expect.eq(5, e.cursor, 'should only seek to end of text') end) mock.patch(e, 'getMousePos', mock.func(2), function() - e:onInput{_MOUSE_L_DOWN=true} + e:onInput{_MOUSE_L=true} expect.eq(3, e.cursor) end) end