mirror of
https://github.com/Bluewhale1337/ElvUIModernized.git
synced 2026-07-27 08:24:44 +00:00
add EditBoxGetCursorPosition & EditBoxSetCursorPosition functions
This commit is contained in:
@@ -7,7 +7,7 @@ local select = select
|
|||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local type = type
|
local type = type
|
||||||
local unpack = unpack
|
local unpack = unpack
|
||||||
local find, format, gmatch, gsub, lower, match, upper = string.find, string.format, string.gmatch, string.gsub, string.lower, string.match, string.upper
|
local find, format, gmatch, gsub, len, lower, match, upper, sub = string.find, string.format, string.gmatch, string.gsub, string.len, string.lower, string.match, string.upper, string.sub
|
||||||
local getn = table.getn
|
local getn = table.getn
|
||||||
--WoW API
|
--WoW API
|
||||||
local debugstack = debugstack
|
local debugstack = debugstack
|
||||||
@@ -412,6 +412,80 @@ function CreateStatusBarTexturePointer(statusbar)
|
|||||||
return f
|
return f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function removeScript(self, script)
|
||||||
|
local func = self:GetScript(script)
|
||||||
|
|
||||||
|
if func then
|
||||||
|
self:SetScript(script, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
return func
|
||||||
|
end
|
||||||
|
|
||||||
|
local nbsp = string.char(255)
|
||||||
|
function EditBoxGetCursorPosition(self)
|
||||||
|
if self == WowLuaFrameEditBox or self == WowLuaFrameCommandEditBox then return 0 end
|
||||||
|
|
||||||
|
if self:GetText() == "" then return 0 end
|
||||||
|
|
||||||
|
local occ = removeScript(self, "OnCursorChanged")
|
||||||
|
local otc = removeScript(self, "OnTextChanged")
|
||||||
|
local ots = removeScript(self, "OnTextSet")
|
||||||
|
|
||||||
|
self:Insert(nbsp)
|
||||||
|
|
||||||
|
local pos = find(self:GetText(), nbsp)
|
||||||
|
if not pos then
|
||||||
|
pos = len(self:GetText())
|
||||||
|
print(format("CursorPosition position for `%s` not found!", self.GetName and self:GetName() or tostring(self)))
|
||||||
|
else
|
||||||
|
self:HighlightText(pos - 1, pos)
|
||||||
|
self:Insert("")
|
||||||
|
end
|
||||||
|
|
||||||
|
if occ then self:SetScript("OnCursorChanged", occ) end
|
||||||
|
if otc then self:SetScript("OnTextChanged", otc) end
|
||||||
|
if ots then self:SetScript("OnTextSet", ots) end
|
||||||
|
|
||||||
|
return pos - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function EditBoxSetCursorPosition(self, pos)
|
||||||
|
if self == WowLuaFrameEditBox or self == WowLuaFrameCommandEditBox then return end
|
||||||
|
|
||||||
|
if self:GetText() == "" then return end
|
||||||
|
|
||||||
|
local occ = removeScript(self, "OnCursorChanged")
|
||||||
|
local otc = removeScript(self, "OnTextChanged")
|
||||||
|
local ots = removeScript(self, "OnTextSet")
|
||||||
|
|
||||||
|
local text = self:GetText()
|
||||||
|
local size = len(text)
|
||||||
|
|
||||||
|
if pos < 0 then
|
||||||
|
pos = 0
|
||||||
|
elseif pos > size then
|
||||||
|
pos = size
|
||||||
|
end
|
||||||
|
|
||||||
|
if pos == 0 then
|
||||||
|
text = sub(text, 0, 1)
|
||||||
|
self:HighlightText(0, 1)
|
||||||
|
self:Insert(nbsp)
|
||||||
|
self:Insert(text)
|
||||||
|
self:HighlightText(0, 1)
|
||||||
|
self:Insert("")
|
||||||
|
else
|
||||||
|
text = sub(text, pos, pos)
|
||||||
|
self:HighlightText(pos - 1, pos)
|
||||||
|
self:Insert(text)
|
||||||
|
end
|
||||||
|
|
||||||
|
if occ then self:SetScript("OnCursorChanged", occ) end
|
||||||
|
if otc then self:SetScript("OnTextChanged", otc) end
|
||||||
|
if ots then self:SetScript("OnTextSet", ots) end
|
||||||
|
end
|
||||||
|
|
||||||
local threatColors = {
|
local threatColors = {
|
||||||
[0] = {0.69, 0.69, 0.69},
|
[0] = {0.69, 0.69, 0.69},
|
||||||
[1] = {1, 1, 0.47},
|
[1] = {1, 1, 0.47},
|
||||||
|
|||||||
@@ -590,8 +590,8 @@ function ScriptErrorsFrame_Update ()
|
|||||||
editBox.text = text;
|
editBox.text = text;
|
||||||
if (prevText ~= text) then
|
if (prevText ~= text) then
|
||||||
editBox:SetText(text);
|
editBox:SetText(text);
|
||||||
|
EditBoxSetCursorPosition(editBox, 0);
|
||||||
editBox:HighlightText(0);
|
editBox:HighlightText(0);
|
||||||
-- editBox:SetCursorPosition(0);
|
|
||||||
else
|
else
|
||||||
ScriptErrorsFrameScrollFrame:UpdateScrollChildRect();
|
ScriptErrorsFrameScrollFrame:UpdateScrollChildRect();
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user