Pyroxenium / Basalt

A UI Framework for CC:Tweaked
MIT License
164 stars 28 forks source link

bug: `Input` doesn't reset the cursor position after getting emptied by `setValue` #35

Closed luiz00martins closed 1 year ago

luiz00martins commented 1 year ago

Describe the bug

The previous position of the Input's cursor is maintained when a setValue call is followed by a setFocus call, even when the input is empty.

Minimal Working Example

--Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

local input = main:addInput('input')
    :setPosition(1, 1)
    :setSize(20, 1)
    :setValue('Some Text')

local button = main:addButton('button')
    :setPosition(1, 2)
    :setSize(20, 1)
    :setValue('Button')
    :onClickUp(function()
        -- Important part
        input:setValue('')
        input:setFocus()
    end)

basalt.autoUpdate()

https://user-images.githubusercontent.com/43142209/196984044-1d5109b7-6ca2-4bff-bf01-b1cfcb68fbf4.mp4

Steps to reproduce the behavior:

  1. Type something in the Input
  2. Clear it with input:setValue('')
  3. Focus on it with input:setFocus()

Expected behavior

The cursor would return to the rightmost side of the input.

Checklist

[x] I am running the latest version.

Erb3 commented 1 year ago

Can reproduce! 👍

Erb3 commented 1 year ago

After my small amount of testing, it seems this was fixed in 3dcdcfd3831b3c5fd659529846c267fe50c3d3d6.