From b22e2122a20d5c1fca8f55cad26b19b86a05b05f Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 17 Oct 2026 07:09:55 -0500 Subject: [PATCH] Multi-char input in one frame is inserted as a paste (no auto-pair/indent; fixes duplicate ')' via text proxy) --- TextEditor.lua | 14 +++++++++++++- tests/t_paste_chars.luau | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/t_paste_chars.luau diff --git a/TextEditor.lua b/TextEditor.lua index 732e9d3..eea1fea 100644 --- a/TextEditor.lua +++ b/TextEditor.lua @@ -2943,7 +2943,19 @@ return function(G) local queue = io.InputQueueCharacters if queue.Size > 0 then -- ignore Ctrl inputs, but need to allow Alt+Ctrl as some keyboards (e.g. German) use AltGR (which is Alt+Ctrl) to input certain characters - if not (ImGui.IsKeyDown(Mod_Ctrl) and not ImGui.IsKeyDown(Mod_Alt)) and not readOnly then + if readOnly then + elseif queue.Size > 1 then + -- [Port] several chars in one frame = a paste delivered as characters (e.g. the Roblox text + -- proxy): insert as one text block, without auto-pairing/auto-indent (else "(x)" became "(x))") + local parts = table.create(queue.Size) + for i = 1, queue.Size do + local character = queue.Data[i] + if character == 10 or character == 9 or character >= 32 then table.insert(parts, utf8.char(character)) end + end + local transaction = self:startTransaction() + self:insertTextIntoAllCursors(transaction, table.concat(parts)) + self:endTransaction(transaction) + elseif not (ImGui.IsKeyDown(Mod_Ctrl) and not ImGui.IsKeyDown(Mod_Alt)) then for i = 1, queue.Size do local character = queue.Data[i] if character == 10 or character >= 32 then diff --git a/tests/t_paste_chars.luau b/tests/t_paste_chars.luau new file mode 100644 index 0000000..801c0c6 --- /dev/null +++ b/tests/t_paste_chars.luau @@ -0,0 +1,23 @@ +local RS = game:GetService("ReplicatedStorage") +local G = require(RS:WaitForChild("ImGui")) +local TextEditor = require(RS:WaitForChild("TextEditor"))(G) +local ImGui = G.ImGui +ImGui.CreateContext(); G.ImGui_ImplRoblox.Init() +local io = ImGui.GetIO() +io.DisplaySize = G.ImVec2(800, 600) +local ed = TextEditor.new() +ed:SetLanguage(TextEditor.Language.Lua()) +ed:SetText("") +for f = 1, 6 do + io.DeltaTime = 1 / 60 + if f == 2 then io:AddMousePosEvent(200, 100); io:AddMouseButtonEvent(0, true) end + if f == 3 then io:AddMouseButtonEvent(0, false) end + if f == 4 then for _, c in utf8.codes("local x = 1\nprint(x)\n ddd") do io:AddInputCharacter(c) end end + ImGui.NewFrame() + ImGui.SetNextWindowPos(G.ImVec2(0, 0)); ImGui.SetNextWindowSize(G.ImVec2(800, 600)) + ImGui.Begin("w"); ed:Render("ed"); ImGui.End() + ImGui.Render() +end +local t = ed:GetText() +assert(t == "local x = 1\nprint(x)\n ddd\n" or t == "local x = 1\nprint(x)\n ddd", ("paste as chars: %q"):format(t)) +print("OK")