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

TextBox Tab Key Removal?

Asked by 5 years ago

When the player is focused on a TextBox and press the Tab key, the text shown in the box does not move, but the really the string now includes a single space.

Example:

TextBox: "This is text."

Player presses Tab.

TextBox: "This is text."

However, TextBox.Text == " This is text."

This causes issues for me, as various texts in my game subsequently do not line up properly because the TextBox doesn't display the space, whereas these other objects (that are mirroring the TextBox) do show the space.

How might I be able stop the Tab key from having any binding whatsoever? I considered simply making it add a space whenever the player presses Tab, but that results in having two spaces in the string, and only one shown, which doesn't fix the issue of non-alignment. Another issue with this solution is that Roblox API gives no indication of where the pre-processor (The blinking line where the player is currently typing) is up to in the string.

Clarification of why that won't work anyway:

(We'll use | to show pre-processor)

TextBox: "Player types this|"

Player hits the left arrow key twice

TextBox: "Player types th|is"

The is no property of a TextBox like Textbox.PreProcessorLocation or TextBox.FocusLocation so even if I could find a way to add a space when Tab is pressed, I would have no idea where to place it, because for all I know the player's pre-processor is in the middle of the TextBox!

Therefore the only possible solution I can think of is to stop Tab from having any effect at all.

How would I do this?

0
Comments don't bump a question, nothing does, as most people only sort by newest theCJarmy7 1293 — 5y

1 answer

Log in to vote
0
Answered by
BanTech 15
5 years ago
Edited 5 years ago

Use string.gsub to replace \t with a space. You can also trim all whitespace from the start and end of the string to prevent them adding spaces/tabs at the start and end.

Here's an example with trimming and then replacing the tabs with spaces.

local rawText = yourTextBox.Text
local trimmedText = rawText:gsub( '^%s+', '' ):gsub( '%s+$', '' )
local cleanText = trimmedText:gsub( '\t', ' ' )
-- text:gsub( ... ) is the same as string.gsub( text, ... )

If you just wanted to replace tabs with spaces, skip out trimmedText. If you want to ignore tabs altogether, change the replacement from ' ' to '' on the cleanText line.

0
Thank you so much! boatbomber 27 — 5y
Ad

Answer this question