Skip to content

Commit

Permalink
Make pasting huge import strings lightning fast
Browse files Browse the repository at this point in the history
Use code provided by Semlar to make pasting a lot faster.
The edit box no longer shows the full contents of the pasted text,
but that's not a huge loss.
  • Loading branch information
InfusOnWoW committed May 27, 2016
1 parent 0890ce7 commit ff0de36
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions Options/WeakAurasOptions.lua
Expand Up @@ -6960,30 +6960,45 @@ function WeakAuras.CreateFrame()
elseif(mode == "table") then
displayStr = WeakAuras.DisplayToTableString(id);
end
importexportbox.editBox:SetMaxBytes(nil);
importexportbox.editBox:SetScript("OnEscapePressed", function() importexport:Close(); end);
importexportbox.editBox:SetScript("OnChar", function() importexportbox:SetText(displayStr); importexportbox.editBox:HighlightText(); end);
importexportbox.editBox:SetScript("OnMouseUp", function() importexportbox.editBox:HighlightText(); end);
importexportbox.editBox:SetScript("OnTextChanged", nil);
importexportbox:SetLabel(id.." - "..#displayStr);
importexportbox.button:Hide();
importexportbox:SetText(displayStr);
importexportbox.editBox:HighlightText();
importexportbox:SetFocus();
end
elseif(mode == "import") then
local textBuffer, i, lastPaste = {}, 0, 0
local function clearBuffer(self)
self:SetScript('OnUpdate', nil)
local pasted = strtrim(table.concat(textBuffer))
importexportbox.editBox:ClearFocus();
pasted = pasted:match( "^%s*(.-)%s*$" );
if (#pasted > 20) then
WeakAuras.ImportString(pasted);
importexportbox:SetLabel(L["Processed %i chars"]:format(i));
importexportbox.editBox:SetMaxBytes(2500);
importexportbox.editBox:SetText(strsub(pasted, 1, 2500));
end
end

importexportbox.editBox:SetScript('OnChar', function(self, c)
if lastPaste ~= GetTime() then
textBuffer, i, lastPaste = {}, 0, GetTime()
self:SetScript('OnUpdate', clearBuffer)
end
i = i + 1
textBuffer[i] = c
end)

importexportbox.editBox:SetText("");
importexportbox.editBox:SetMaxBytes(2500);
importexportbox.editBox:SetScript("OnEscapePressed", function() importexport:Close(); end);
importexportbox.editBox:SetScript("OnChar", nil);
importexportbox.editBox:SetScript("OnMouseUp", nil);
importexportbox.editBox:SetScript("OnTextChanged", function()
local str = importexportbox:GetText();
str = str:match( "^%s*(.-)%s*$" )
importexportbox:SetLabel(""..#str);
if(#str > 20) then
WeakAuras.ImportString(str);
end
end);
importexportbox:SetText("");
importexportbox:SetLabel("0");
importexportbox:SetLabel(L["Paste text below"]);
importexportbox:SetFocus();
end
end
Expand Down

0 comments on commit ff0de36

Please sign in to comment.