Added paste
This commit is contained in:
@@ -34,6 +34,7 @@ Input.defineProperty(Input, "replaceChar", {default = nil, type = "string", canT
|
|||||||
Input.defineEvent(Input, "mouse_click")
|
Input.defineEvent(Input, "mouse_click")
|
||||||
Input.defineEvent(Input, "key")
|
Input.defineEvent(Input, "key")
|
||||||
Input.defineEvent(Input, "char")
|
Input.defineEvent(Input, "char")
|
||||||
|
Input.defineEvent(Input, "paste")
|
||||||
|
|
||||||
--- @shortDescription Creates a new Input instance
|
--- @shortDescription Creates a new Input instance
|
||||||
--- @return Input object The newly created Input instance
|
--- @return Input object The newly created Input instance
|
||||||
@@ -192,6 +193,24 @@ function Input:blur()
|
|||||||
self:updateRender()
|
self:updateRender()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Input:paste(content)
|
||||||
|
if not self.get("focused") then return false end
|
||||||
|
local text = self.get("text")
|
||||||
|
local pos = self.get("cursorPos")
|
||||||
|
local maxLength = self.get("maxLength")
|
||||||
|
local pattern = self.get("pattern")
|
||||||
|
local newText = text:sub(1, pos - 1) .. content .. text:sub(pos)
|
||||||
|
if maxLength and #newText > maxLength then
|
||||||
|
newText = newText:sub(1, maxLength)
|
||||||
|
end
|
||||||
|
if pattern and not newText:match(pattern) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
self.set("text", newText)
|
||||||
|
self.set("cursorPos", pos + #content)
|
||||||
|
self:updateViewport()
|
||||||
|
end
|
||||||
|
|
||||||
--- @shortDescription Renders the input element
|
--- @shortDescription Renders the input element
|
||||||
--- @protected
|
--- @protected
|
||||||
function Input:render()
|
function Input:render()
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ TextBox.defineEvent(TextBox, "mouse_click")
|
|||||||
TextBox.defineEvent(TextBox, "key")
|
TextBox.defineEvent(TextBox, "key")
|
||||||
TextBox.defineEvent(TextBox, "char")
|
TextBox.defineEvent(TextBox, "char")
|
||||||
TextBox.defineEvent(TextBox, "mouse_scroll")
|
TextBox.defineEvent(TextBox, "mouse_scroll")
|
||||||
|
TextBox.defineEvent(TextBox, "paste")
|
||||||
|
|
||||||
--- Creates a new TextBox instance
|
--- Creates a new TextBox instance
|
||||||
--- @shortDescription Creates a new TextBox instance
|
--- @shortDescription Creates a new TextBox instance
|
||||||
@@ -235,6 +236,23 @@ function TextBox:mouse_click(button, x, y)
|
|||||||
return false
|
return false
|
||||||
end
|
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
|
--- Sets the text of the TextBox
|
||||||
--- @shortDescription Sets the text of the TextBox
|
--- @shortDescription Sets the text of the TextBox
|
||||||
--- @param text string The text to set
|
--- @param text string The text to set
|
||||||
|
|||||||
Reference in New Issue
Block a user