From f0a534c098c90128bdc56e0370db1988148f1943 Mon Sep 17 00:00:00 2001 From: Pinya <800pin.ru@gmail.com> Date: Thu, 22 Nov 2018 14:01:14 +0300 Subject: [PATCH] fix EditBox Get/SetCursorPosition workaround for Numeric and with character limits --- !Compatibility/api/wowAPI.lua | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/!Compatibility/api/wowAPI.lua b/!Compatibility/api/wowAPI.lua index ffe6190..e4cdb02 100644 --- a/!Compatibility/api/wowAPI.lua +++ b/!Compatibility/api/wowAPI.lua @@ -430,6 +430,18 @@ function EditBoxGetCursorPosition(self) local otc = removeScript(self, "OnTextChanged") 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) local pos = find(self:GetText(), nbsp) @@ -441,6 +453,13 @@ function EditBoxGetCursorPosition(self) self:Insert("") end + if charsChanged then + self:SetMaxLetters(maxChars) + end + if numeric then + self:SetNumeric(true) + 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 @@ -467,12 +486,31 @@ function EditBoxSetCursorPosition(self, pos) end 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) self:HighlightText(0, 1) self:Insert(nbsp) self:Insert(text) self:HighlightText(0, 1) self:Insert("") + + if charsChanged then + self:SetMaxLetters(maxChars) + end + if numeric then + self:SetNumeric(true) + end else text = sub(text, pos, pos) self:HighlightText(pos - 1, pos)