Compare commits
6
Commits
master
..
826fc0d20d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
826fc0d20d | ||
|
|
8e1ba598eb | ||
|
|
369156c00a | ||
|
|
8efb0d0051 | ||
|
|
49db6286c6 | ||
|
|
75bdb75051 |
No files matched your search
@@ -1,3 +1,2 @@
|
||||
.gitattributes export-ignore
|
||||
tools/upstream/** linguist-vendored=true
|
||||
love/** linguist-generated=true
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
[submodule "tools/core"]
|
||||
path = tools/core
|
||||
url = https://github.com/4DBug/imgui-luau.git
|
||||
url = https://git.bug.tools/bug/imgui-luau.git
|
||||
+12
-86
@@ -140,7 +140,6 @@ return function(G)
|
||||
end
|
||||
|
||||
-- [Port] no east asian width tables: every glyph is one column wide
|
||||
@native
|
||||
function CodePoint.getGlyphWidth(codepoint)
|
||||
return 1
|
||||
end
|
||||
@@ -160,7 +159,7 @@ return function(G)
|
||||
end
|
||||
|
||||
function Document.new()
|
||||
local self = setmetatable({ lines = {}, updated = false, version = 0 }, Document)
|
||||
local self = setmetatable({ lines = {}, updated = false }, Document)
|
||||
self:appendLine()
|
||||
return self
|
||||
end
|
||||
@@ -222,7 +221,6 @@ return function(G)
|
||||
|
||||
-- [Port] updateIndents skipped (used by rendering only)
|
||||
self.updated = true
|
||||
self.version = self.version + 1
|
||||
end
|
||||
|
||||
-- insert/delete part of the document's text (strings are UTF-8 encoded)
|
||||
@@ -264,13 +262,10 @@ return function(G)
|
||||
|
||||
-- mark affected lines as changed
|
||||
for j = start.line, e.line do
|
||||
local changed = self:at(j)
|
||||
changed.needsColorizing = true
|
||||
changed.columns = nil
|
||||
self:at(j).needsColorizing = true
|
||||
end
|
||||
|
||||
self.updated = true
|
||||
self.version = self.version + 1
|
||||
return e
|
||||
end
|
||||
|
||||
@@ -301,9 +296,7 @@ return function(G)
|
||||
|
||||
-- mark line and document as changed
|
||||
startLine.needsColorizing = true
|
||||
startLine.columns = nil
|
||||
self.updated = true
|
||||
self.version = self.version + 1
|
||||
end
|
||||
|
||||
-- get document text as UTF-8
|
||||
@@ -323,20 +316,7 @@ return function(G)
|
||||
end
|
||||
|
||||
-- get part of document text (returned strings are UTF-8 encoded)
|
||||
-- [Port] the last result is kept until the document changes (version) or another section is asked for: the editor
|
||||
-- hands the selected text to the platform (IME / Roblox text proxy) every frame
|
||||
function Document:getSectionText(start, e)
|
||||
local memo = self.sectionMemo
|
||||
if memo and memo[1] == self.version and memo[2] == start.line and memo[3] == start.index and memo[4] == e.line and memo[5] == e.index then
|
||||
return memo[6]
|
||||
end
|
||||
local text = self:getSectionTextUncached(start, e)
|
||||
if not memo then memo = {}; self.sectionMemo = memo end
|
||||
memo[1], memo[2], memo[3], memo[4], memo[5], memo[6] = self.version, start.line, start.index, e.line, e.index, text
|
||||
return text
|
||||
end
|
||||
|
||||
function Document:getSectionTextUncached(start, e)
|
||||
local parts = {}
|
||||
local lineNo = start.line
|
||||
local index = start.index
|
||||
@@ -1643,7 +1623,6 @@ return function(G)
|
||||
local openers = { [40] = 41, [123] = 125, [91] = 93 } -- ( { [
|
||||
local closers = { [41] = 40, [125] = 123, [93] = 91 } -- ) } ]
|
||||
|
||||
@native
|
||||
local function isBracketCandidate(glyph)
|
||||
local color = glyph.color
|
||||
return color == Color.punctuation or color == Color.matchingBracketLevel1 or color == Color.matchingBracketLevel2
|
||||
@@ -1663,7 +1642,6 @@ return function(G)
|
||||
local bracketColors = { Color.matchingBracketLevel1, Color.matchingBracketLevel2, Color.matchingBracketLevel3 }
|
||||
|
||||
-- [Port] invisible (indentation based) blocks are not generated yet (no language uses indentationForBlocks)
|
||||
@native
|
||||
function Bracketeer:update(config, document)
|
||||
-- see if the configuration changed
|
||||
local configChanged = self.showMatchingBrackets ~= config.showMatchingBrackets or self.language ~= config.language
|
||||
@@ -1691,12 +1669,10 @@ return function(G)
|
||||
local level = 0
|
||||
|
||||
-- process all the glyphs
|
||||
-- [Port] the (disjoint) opener/closer lookups come before the colour test: most glyphs are neither
|
||||
for l, line in ipairs(document.lines) do
|
||||
for i, glyph in ipairs(line) do
|
||||
local codepoint = glyph.codepoint
|
||||
-- handle a "bracket opener" that is not in a comment, string or preprocessor statement
|
||||
if openers[codepoint] and isBracketCandidate(glyph) then
|
||||
if isBracketCandidate(glyph) and openers[glyph.codepoint] then
|
||||
-- start a new level
|
||||
list[#list + 1] = { startChar = glyph.codepoint, start = newDocPos(l - 1, i - 1), endChar = 0, ["end"] = newDocPos(0, 0), level = level, visible = true }
|
||||
levels[#levels + 1] = #list
|
||||
@@ -1704,7 +1680,7 @@ return function(G)
|
||||
level = level + 1
|
||||
|
||||
-- handle a "bracket closer" that is not in a comment, string or preprocessor statement
|
||||
elseif closers[codepoint] and isBracketCandidate(glyph) then
|
||||
elseif isBracketCandidate(glyph) and closers[glyph.codepoint] then
|
||||
if #levels > 0 then
|
||||
local lastBracket = list[table.remove(levels)]
|
||||
level = level - 1
|
||||
@@ -2041,14 +2017,12 @@ return function(G)
|
||||
self.bracketeer:resetUpdated()
|
||||
|
||||
-- get "new" total editor size in pixels
|
||||
-- [Port] the widest line is looked for only when the document (or tab size) changed (every edit goes through
|
||||
-- Document:setUtf8Text/insertText/deleteText, which set document.updated), using the column count cached on
|
||||
-- each line (cleared by insertText/deleteText on the lines they change; new lines have none)
|
||||
-- ponytail: column count rescans every line each call, cache per line if huge documents get slow
|
||||
local columns = 0
|
||||
local tabSize = self.config.tabSize
|
||||
local columns = self.maxColumns
|
||||
if documentChanged or columns == nil or self.maxColumnsDocument ~= self.document or self.maxColumnsTabSize ~= tabSize then
|
||||
columns = self.maxLineColumns(self.document.lines, tabSize)
|
||||
self.maxColumns, self.maxColumnsDocument, self.maxColumnsTabSize = columns, self.document, tabSize
|
||||
for _, line in ipairs(self.document.lines) do
|
||||
local c = self.lineColumns(line, tabSize)
|
||||
if c > columns then columns = c end
|
||||
end
|
||||
local width = self.textLeftOffset + columns * self.glyphSize.x + self.cursorWidth
|
||||
local height = self.document:size() * self.glyphSize.y
|
||||
@@ -2218,7 +2192,6 @@ return function(G)
|
||||
|
||||
TextEditor.Scroll = { alignTop = 0, alignMiddle = 1, alignBottom = 2 }
|
||||
|
||||
@native
|
||||
local function glyphColumns(codepoint, column, tabSize)
|
||||
if codepoint == 9 then
|
||||
return tabSize - column % tabSize
|
||||
@@ -2226,7 +2199,6 @@ return function(G)
|
||||
return CodePoint.getGlyphWidth(codepoint)
|
||||
end
|
||||
|
||||
@native
|
||||
function TextEditor.lineColumns(line, tabSize)
|
||||
local column = 0
|
||||
for i = 1, #line do
|
||||
@@ -2235,23 +2207,6 @@ return function(G)
|
||||
return column
|
||||
end
|
||||
|
||||
-- [Port] widest line in columns, through the per-line cache (line.columns for line.columnsTabSize)
|
||||
@native
|
||||
function TextEditor.maxLineColumns(lines, tabSize)
|
||||
local lineColumns = TextEditor.lineColumns
|
||||
local columns = 0
|
||||
for l = 1, #lines do
|
||||
local line = lines[l]
|
||||
local c = line.columns
|
||||
if c == nil or line.columnsTabSize ~= tabSize then
|
||||
c = lineColumns(line, tabSize)
|
||||
line.columns, line.columnsTabSize = c, tabSize
|
||||
end
|
||||
if c > columns then columns = c end
|
||||
end
|
||||
return columns
|
||||
end
|
||||
|
||||
local function isPairOpener(ch) return ch == 123 or ch == 91 or ch == 40 or ch == 39 or ch == 34 end
|
||||
local function toPairCloser(ch)
|
||||
if ch == 123 then return 125 elseif ch == 91 then return 93 elseif ch == 40 then return 41 end
|
||||
@@ -2259,7 +2214,6 @@ return function(G)
|
||||
end
|
||||
|
||||
-- coordinate conversions
|
||||
@native
|
||||
function TextEditor:docPos2VisPos(pos)
|
||||
local line = self.document:at(pos.line)
|
||||
local tabSize = self.config.tabSize
|
||||
@@ -2641,7 +2595,6 @@ return function(G)
|
||||
-- TextEditor::renderMatchingBracketLines
|
||||
--
|
||||
|
||||
@native
|
||||
function TextEditor:renderMatchingBracketLines()
|
||||
if self.config.showMatchingBrackets and #self.bracketeer.list > 0 then
|
||||
local active = self.bracketeer:getEnclosingBrackets(self.cursors:getMain():getInteractiveEnd())
|
||||
@@ -2668,7 +2621,6 @@ return function(G)
|
||||
-- TextEditor::renderText
|
||||
--
|
||||
|
||||
@native
|
||||
function TextEditor:renderText()
|
||||
local glyphSize = self.glyphSize
|
||||
local tabSize = self.config.tabSize
|
||||
@@ -2681,7 +2633,6 @@ return function(G)
|
||||
local rowY = self.cursorScreenPos.y + self.firstVisibleRow * glyphSize.y
|
||||
local firstRenderableColumn = math.floor(self.firstVisibleColumn / tabSize) * tabSize
|
||||
local lastVisibleColumn = self.lastVisibleColumn
|
||||
local charPos = ImVec2(0, 0) -- [Port] scratch glyph position (RenderChar only reads it)
|
||||
|
||||
-- only process all visible rows
|
||||
for i = self.firstVisibleRow, self.lastVisibleRow do
|
||||
@@ -2716,8 +2667,7 @@ return function(G)
|
||||
|
||||
-- handle regular glyphs
|
||||
elseif column >= firstRenderableColumn then
|
||||
charPos.x, charPos.y = glyphX, rowY
|
||||
font:RenderChar(drawList, fontSize, charPos, palette[glyph.color], codepoint)
|
||||
font:RenderChar(drawList, fontSize, ImVec2(glyphX, rowY), palette[glyph.color], codepoint)
|
||||
end
|
||||
|
||||
column = column + width
|
||||
@@ -2993,19 +2943,7 @@ 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 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
|
||||
if not (ImGui.IsKeyDown(Mod_Ctrl) and not ImGui.IsKeyDown(Mod_Alt)) and not readOnly then
|
||||
for i = 1, queue.Size do
|
||||
local character = queue.Data[i]
|
||||
if character == 10 or character >= 32 then
|
||||
@@ -3016,19 +2954,7 @@ return function(G)
|
||||
queue:resize(0)
|
||||
end
|
||||
|
||||
-- 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
|
||||
-- [Port] TODO: PlatformImeData (IME position)
|
||||
|
||||
-- tell app to ignore keyboard inputs
|
||||
ImGui.SetNextFrameWantCaptureKeyboard(true)
|
||||
|
||||
-4498
File diff suppressed because it is too large.
Load diff
@@ -1,56 +0,0 @@
|
||||
-- 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")
|
||||
@@ -1,23 +0,0 @@
|
||||
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")
|
||||
@@ -1,40 +0,0 @@
|
||||
-- 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)
|
||||
+1
-1
Submodule tools/core updated: b0e4f105f5...7cd2ee010a.
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
# Regenerates love/: Lua 5.1 (LÖVE/LuaJIT) copies of the Luau sources. Needs darklua + python3.
|
||||
set -e
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p love
|
||||
CFG=$(mktemp)
|
||||
echo '{ "generator": "retain_lines", "rules": ["remove_types", "remove_compound_assignment", "remove_if_expression", "remove_continue", "remove_interpolated_string", "remove_floor_division"] }' > "$CFG"
|
||||
for f in TextEditor.lua; do
|
||||
out="love/$(basename "$f")"
|
||||
darklua process -c "$CFG" "$f" "$out"
|
||||
python3 - "$out" <<'PY'
|
||||
import re, sys
|
||||
p = sys.argv[1]; src = open(p).read()
|
||||
src = re.sub(r"^\s*@native\s*$", "", src, flags=re.M)
|
||||
# Luau generalized iteration: for k, v in t do -> for k, v in __iter(t) do
|
||||
src = re.sub(r"^([ \t]*for[ \t]+[\w][\w, \t]*[ \t]in[ \t]+)([^\n]*?)([ \t]+do\b)", r"\1__iter(\2)\3", src, flags=re.M)
|
||||
head = ("-- GENERATED by tools/love.sh from the Luau source - do not edit\n"
|
||||
"local function __iter(t, ...) if type(t) ~= 'table' or (getmetatable(t) and getmetatable(t).__call) then return t, ... end "
|
||||
"local n, i, k = #t, 0, nil return function() if i < n then i = i + 1 return i, t[i] end "
|
||||
"repeat k = next(t, k) until k == nil or type(k) ~= 'number' or k < 1 or k > n or k % 1 ~= 0 if k ~= nil then return k, t[k] end end end "
|
||||
"table.create = table.create or function(n, v) local t = {} if v ~= nil then for i = 1, n do t[i] = v end end return t end "
|
||||
"table.clone = table.clone or function(t) local c = {} for k, v in pairs(t) do c[k] = v end return setmetatable(c, getmetatable(t)) end "
|
||||
"math.clamp = math.clamp or function(x, a, b) return math.max(a, math.min(b, x)) end "
|
||||
"math.sign = math.sign or function(x) return x > 0 and 1 or (x < 0 and -1 or 0) end "
|
||||
"math.round = math.round or function(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end\n")
|
||||
open(p, "w").write(head + src)
|
||||
PY
|
||||
done
|
||||
rm -f "$CFG"
|
||||
Reference in new issue
Block a user