Performance: widest line cached (recomputed only when the document or tab size changed, from per-line column counts cleared by insertText/deleteText), Bracketeer:update tests the opener/closer tables before the colour, the last getSectionText result kept until the document version or range changes (the selected text handed to the IME / text proxy every frame), scratch glyph position in renderText, @native on the per-glyph loops (glyphColumns, lineColumns, maxLineColumns, getGlyphWidth, Bracketeer:update, isBracketCandidate, renderText, docPos2VisPos, renderMatchingBracketLines); tests/t_caches.luau checks the caches against fresh computations (3000-line Lua file, headless --roblox, lib med: idle 12.4 -> 1.4 ms, typing every frame 22.7 -> 6.3 ms; draw data unchanged incl. scroll/typing/selection/drag, LÖVE draw data unchanged)
This commit is contained in:
1 parent
a3efb2bf46
commit
0e91c4fee3
3 files changed
+171
-20
No files matched your search
@@ -0,0 +1,56 @@
|
||||
-- Cached state stays equal to a fresh computation: widest line (per-line column cache) and the selected text memo,
|
||||
-- through edits (single/multi-line inserts and deletes, tabs, undo/redo), tab size changes and SetText.
|
||||
local RS = game:GetService("ReplicatedStorage")
|
||||
local G = require(RS:WaitForChild("ImGui"))
|
||||
local TextEditor = require(RS:WaitForChild("TextEditor"))(G)
|
||||
local P = TextEditor.DocPos.new
|
||||
G.ImGui.CreateContext()
|
||||
|
||||
local function eq(a, b, msg)
|
||||
assert(a == b, (msg or "") .. ": expected " .. tostring(b) .. ", got " .. tostring(a))
|
||||
end
|
||||
|
||||
local e = TextEditor.new()
|
||||
local function check(msg)
|
||||
e:updateState()
|
||||
local columns = 0
|
||||
for _, line in ipairs(e.document.lines) do columns = math.max(columns, TextEditor.lineColumns(line, e.config.tabSize)) end
|
||||
eq(e.maxColumns, columns, msg .. " columns")
|
||||
local c = e.cursors:getCurrent()
|
||||
eq(e:GetSelectedText(), e.document:getSectionTextUncached(c:getSelectionStart(), c:getSelectionEnd()), msg .. " selected text")
|
||||
end
|
||||
|
||||
e:SetText("short\na much longer line here\n\tx\nmid line")
|
||||
check("set")
|
||||
e:SelectRegion(P(1, 0), P(1, 6))
|
||||
check("select")
|
||||
e:ReplaceTextInAllCursors("")
|
||||
check("delete in line")
|
||||
e:SelectRegion(P(0, 2), P(2, 1))
|
||||
check("select multi")
|
||||
e:ReplaceTextInAllCursors("")
|
||||
check("delete multi")
|
||||
e:SetCursor(P(0, 1))
|
||||
e:ReplaceTextInAllCursors("0123456789012345678901234567890123456789\nnext\t\tline")
|
||||
check("insert multi")
|
||||
e:SelectRegion(P(1, 0), P(1, 4))
|
||||
check("select after insert")
|
||||
e:Undo()
|
||||
check("undo")
|
||||
e:Redo()
|
||||
check("redo")
|
||||
e:SetTabSize(8)
|
||||
check("tab size")
|
||||
e:SetText("a\n\t\tb")
|
||||
check("set again")
|
||||
e:SelectAll()
|
||||
check("select all")
|
||||
e:ReplaceTextInAllCursors("x")
|
||||
check("replace all")
|
||||
-- same section asked for again after an edit inside it
|
||||
e:SetText("hello world")
|
||||
eq(e:GetSectionText(P(0, 0), P(0, 5)), "hello", "section")
|
||||
e:SetCursor(P(0, 1))
|
||||
e:ReplaceTextInAllCursors("J")
|
||||
eq(e:GetSectionText(P(0, 0), P(0, 5)), "hJell", "section after edit")
|
||||
print("OK")
|
||||
Reference in new issue
Block a user