Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Move cursor to start of text box?

Asked by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

I made a script that does this

  1. when text box focus is lost
  2. clear text
  3. wait until enter is released
  4. capture focus again
  5. replace the text

to try and move the cursor to the beginning of the textbox when the focus was lost. It works visually and you can see the cursor at the beginning of the box, but when you actually input another letter it just acts as if the cursor is at the end.

here is the script, if you paste it inside a textbox you can see the problem. Is this a bug?

local sp = script.Parent

sp.ClearTextOnFocus = false

sp.FocusLost:connect(function(enterpressed)

    if enterpressed == true then

        local text = sp.Text
        sp.Text = ""

        repeat
            local key = game:GetService("UserInputService").InputEnded:wait()
        until key.KeyCode == Enum.KeyCode.Return

        sp:CaptureFocus()

        sp.Text = text

    end

end)

Answer this question