Hey, so I get that this is obviously a bug and should be fixed, but at the moment it isn’t so I just want to hack a solution in for now.
Anyway, I want to be able to navigate my TextBox, which has MultiLine set to true, using the up and down arrows.
Here’s the code I have so far, it allows me to get both the current line that I’m on as well as the column I’m in, this will be important later.
local UIS = game:GetService("UserInputService")
local InputArea = script.Parent
function Split(Str, Del)
local Result = {}
for Match in (Str..Del):gmatch("(.-)"..Del) do
table.insert(Result, Match)
end
return Result
end
function GetLineNumber()
local Selection = InputArea.Text:sub(0, InputArea.CursorPosition-1)
local _, Count = Selection:gsub("\n", "")
return Count + 1
end
function GetSelection(Line)
local Selection = InputArea.CursorPosition
local Lines = Split(InputArea.Text, "\n")
for i = 1, Line-1 do
Selection -= Lines[i]:len()
end
return Selection
end
function GetColumnNumber()
local Line = GetLineNumber()
local Selection = GetSelection(Line) - (Line - 1)
return Selection
end
UIS.InputBegan:Connect(function(Input, IsTyping)
if not IsTyping then return end
if not script.Parent:IsFocused() then return end
if Input.KeyCode == Enum.KeyCode.Up then
-- Need to subtract `InputArea.CursorPosition` by an amount to make it exactly one line above.
elseif Input.KeyCode == Enum.KeyCode.Down then
-- Need to add an amount to `InputArea.CursorPosition` to make it exactly one line below.
end
end)
So, obviously, I’ll need to put code in to increment or decrement the TextBox.CursorPosition attribute. The amount it will need to be changed by depened on the column it’s in, and also the length of the line that it’s moving to.
The issue obviously being, how in the world do I figure out exactly how much it needs to be incremented or decremented by?
Sorry if this is pretty complex, but I’m completely stuck.