Added paste

This commit is contained in:
Robert Jelic
2025-05-11 03:13:57 +02:00
parent f7c4165aa4
commit d4f875836d
2 changed files with 37 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ TextBox.defineEvent(TextBox, "mouse_click")
TextBox.defineEvent(TextBox, "key")
TextBox.defineEvent(TextBox, "char")
TextBox.defineEvent(TextBox, "mouse_scroll")
TextBox.defineEvent(TextBox, "paste")
--- Creates a new TextBox instance
--- @shortDescription Creates a new TextBox instance
@@ -235,6 +236,23 @@ function TextBox:mouse_click(button, x, y)
return false
end
function TextBox:paste(text)
if not self.get("editable") or not self.get("focused") then return false end
local lines = self.get("lines")
local cursorX = self.get("cursorX")
local cursorY = self.get("cursorY")
for char in text:gmatch(".") do
if char == "\n" then
newLine(self)
else
insertChar(self, char)
end
end
return true
end
--- Sets the text of the TextBox
--- @shortDescription Sets the text of the TextBox
--- @param text string The text to set