From 7190f1c983958fb048a70b0eb59c94beafaed785 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 17 Oct 2026 04:25:28 -0500 Subject: [PATCH] PlatformImeData: IME position + SelectedText for Roblox text proxy; bump core --- TextEditor.lua | 14 +++++++++++++- tests/t_textproxy.luau | 40 ++++++++++++++++++++++++++++++++++++++++ tools/core | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/t_textproxy.luau diff --git a/TextEditor.lua b/TextEditor.lua index 36b0dc0..732e9d3 100644 --- a/TextEditor.lua +++ b/TextEditor.lua @@ -2954,7 +2954,19 @@ return function(G) queue:resize(0) end - -- [Port] TODO: PlatformImeData (IME position) + -- notify OS of text input position for IME (and, in the port, the selected text for the Roblox text proxy) + if not readOnly then + local ime = ImGui.GetCurrentContext().PlatformImeData + ime.WantVisible = true + ime.WantTextInput = true + -- at the main cursor: the top left of its line (as in Dear ImGui's InputText) + local row, column = self:docPos2VisPos(self:getCursorPosition(cursors:getMainIndex())) + ime.InputPos = ImVec2(self.cursorScreenPos.x + self.textLeftOffset + column * self.glyphSize.x - 1, self.cursorScreenPos.y + row * self.glyphSize.y) + ime.InputLineHeight = self.glyphSize.y + local viewport = ImGui.GetCurrentWindow().Viewport + if viewport then ime.ViewportId = viewport.ID end + ime.SelectedText = self:GetSelectedText() or "" + end -- tell app to ignore keyboard inputs ImGui.SetNextFrameWantCaptureKeyboard(true) diff --git a/tests/t_textproxy.luau b/tests/t_textproxy.luau new file mode 100644 index 0000000..0238c0a --- /dev/null +++ b/tests/t_textproxy.luau @@ -0,0 +1,40 @@ +-- Roblox text proxy: the editor's selection is mirrored into the proxy TextBox, and proxy typing is inserted. +local RS = game:GetService("ReplicatedStorage") +local G = require(RS:WaitForChild("ImGui")) +local TextEditor = require(RS:WaitForChild("TextEditor"))(G) +local ImGui, ImVec2 = G.ImGui, G.ImVec2 +ImGui.CreateContext() +G.ImGui_ImplRoblox.Init() +G.ImGui_ImplRoblox.SetTextProxy(true) +local io = ImGui.GetIO() + +local editor = TextEditor.new() +editor:SetText("hello world") + +local proxy +local frame = 0 +game:GetService("RunService").Stepped:Connect(function() + frame += 1 + if frame > 30 then return end + G.ImGui_ImplRoblox.NewFrame() + io.DeltaTime = 1 / 60 + proxy = proxy or game:GetService("Players").LocalPlayer.PlayerGui.ImGui.TextProxy + if frame == 5 then io:AddMousePosEvent(400, 60) end + if frame == 6 then io:AddMouseButtonEvent(0, true) end + if frame == 7 then io:AddMouseButtonEvent(0, false) end + if frame == 9 then editor:SelectAll() end + if frame == 16 then proxy.Text = "bye" end + ImGui.NewFrame() + ImGui.SetNextWindowPos(ImVec2(0, 0)) + ImGui.SetNextWindowSize(ImVec2(600, 400)) + ImGui.Begin("Editor") + editor:Render("##editor") + ImGui.End() + ImGui.Render() + G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData()) + if frame == 14 then assert(proxy.Text == "hello world", "mirror: " .. proxy.Text) end + if frame == 25 then + assert(editor:GetText() == "bye\n", "inserted: " .. editor:GetText()) + print("OK") + end +end) diff --git a/tools/core b/tools/core index 7cd2ee0..b0e4f10 160000 --- a/tools/core +++ b/tools/core @@ -1 +1 @@ -Subproject commit 7cd2ee010a265543e4cdc09145507232afba3354 +Subproject commit b0e4f105f5820f4165ca990d966924f5b582925c