fix EditBox Get/SetCursorPosition

workaround for Numeric and with character limits
This commit is contained in:
Pinya
2018-11-22 14:01:14 +03:00
parent f0a2499585
commit f0a534c098
+38
View File
@@ -430,6 +430,18 @@ function EditBoxGetCursorPosition(self)
local otc = removeScript(self, "OnTextChanged") local otc = removeScript(self, "OnTextChanged")
local ots = removeScript(self, "OnTextSet") local ots = removeScript(self, "OnTextSet")
local charsChanged, numeric
local maxChars = self:GetMaxLetters()
if maxChars == self:GetNumLetters() then
self:SetMaxLetters(maxChars + 1)
charsChanged = true
end
if self:IsNumeric() then
self:SetNumeric(false)
numeric = true
end
self:Insert(nbsp) self:Insert(nbsp)
local pos = find(self:GetText(), nbsp) local pos = find(self:GetText(), nbsp)
@@ -441,6 +453,13 @@ function EditBoxGetCursorPosition(self)
self:Insert("") self:Insert("")
end end
if charsChanged then
self:SetMaxLetters(maxChars)
end
if numeric then
self:SetNumeric(true)
end
if occ then self:SetScript("OnCursorChanged", occ) end if occ then self:SetScript("OnCursorChanged", occ) end
if otc then self:SetScript("OnTextChanged", otc) end if otc then self:SetScript("OnTextChanged", otc) end
if ots then self:SetScript("OnTextSet", ots) end if ots then self:SetScript("OnTextSet", ots) end
@@ -467,12 +486,31 @@ function EditBoxSetCursorPosition(self, pos)
end end
if pos == 0 then if pos == 0 then
local charsChanged, numeric
local maxChars = self:GetMaxLetters()
if maxChars == self:GetNumLetters() then
self:SetMaxLetters(maxChars + 1)
charsChanged = true
end
if self:IsNumeric() then
self:SetNumeric(false)
numeric = true
end
text = sub(text, 0, 1) text = sub(text, 0, 1)
self:HighlightText(0, 1) self:HighlightText(0, 1)
self:Insert(nbsp) self:Insert(nbsp)
self:Insert(text) self:Insert(text)
self:HighlightText(0, 1) self:HighlightText(0, 1)
self:Insert("") self:Insert("")
if charsChanged then
self:SetMaxLetters(maxChars)
end
if numeric then
self:SetNumeric(true)
end
else else
text = sub(text, pos, pos) text = sub(text, pos, pos)
self:HighlightText(pos - 1, pos) self:HighlightText(pos - 1, pos)