we kept editfield as MOUSE_L for click and drag

develop
myk002 2022-11-21 17:51:04 -08:00
parent db516d9474
commit c9cf5ecca8
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 4 additions and 4 deletions

@ -334,7 +334,7 @@ function EditField:onInput(keys)
elseif keys._MOUSE_L then elseif keys._MOUSE_L then
local mouse_x, mouse_y = self:getMousePos() local mouse_x, mouse_y = self:getMousePos()
if mouse_x then 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 return true
end end
elseif keys._STRING then elseif keys._STRING then

@ -40,17 +40,17 @@ function test.editfield_click()
expect.eq(5, e.cursor) expect.eq(5, e.cursor)
mock.patch(e, 'getMousePos', mock.func(0), function() mock.patch(e, 'getMousePos', mock.func(0), function()
e:onInput{_MOUSE_L_DOWN=true} e:onInput{_MOUSE_L=true}
expect.eq(1, e.cursor) expect.eq(1, e.cursor)
end) end)
mock.patch(e, 'getMousePos', mock.func(20), function() 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') expect.eq(5, e.cursor, 'should only seek to end of text')
end) end)
mock.patch(e, 'getMousePos', mock.func(2), function() mock.patch(e, 'getMousePos', mock.func(2), function()
e:onInput{_MOUSE_L_DOWN=true} e:onInput{_MOUSE_L=true}
expect.eq(3, e.cursor) expect.eq(3, e.cursor)
end) end)
end end