I have an autocomplete system in place and when you press Tab it’d autocomplete to one of the matched words but it adds an space once it’s filled, how do you remove that space or make it so it doesn’t add entirely?
For example;
If I had a word in my autocomplete module called hello
and I began to type the in chat then it’d display a TextButton beneath the Chat Bar displaying Hello
and you can click it to autocomplete the message and it wouldn’t have any spaces and it’d just be Hello
but when I press Tab then it fills the message in the TextBox for the Chat but it’d be Hello |
but with the space in the place of the |
.
So how would I prevent that from happening?
Here is the code;
if #matches > 0 then
self.GuiObjects.SuggestionFrame.Size = UDim2.new(1,0,0,48)
recommendationConnection = UserInputService.InputBegan:Connect(function(input, processed)
if processed and input.KeyCode == Enum.KeyCode.Tab and self.TextBox.CursorPosition ~= -1 then
recommendationPass = true
local children = self.GuiObjects.SuggestionSubframe:GetChildren()
table.sort(children, function(a,b) if a:IsA("UIListLayout") then return true elseif b:IsA("UIListLayout") then return false end return (a.Name:lower() < b.Name:lower()) end)
recommendationIndex = (recommendationIndex) % (#children-1) + 2
print(recommendationIndex)
local addLen = 0
if children[recommendationIndex-1]:IsA("TextButton") then
children[recommendationIndex-1].TextTransparency = 0.4
addLen = string.len(children[recommendationIndex-1].Name)
end
children[recommendationIndex].TextTransparency = 0
for _, match in ipairs(matches) do
if match[1] == children[recommendationIndex].Name then
TextBox.Text = string.sub(TextBox.Text, 1, string.len(TextBox.Text) - string.len(match[2]))..match[1]
TextBox.CursorPosition = string.len(TextBox.Text) + 1
break
end
end
recommendationPass = false
end
end)
else
self.GuiObjects.SuggestionFrame.Size = UDim2.new(1,0,0,0)
end