Skip to content

Commit

Permalink
🐛 #5: Fixed a bug where the item would not be added
Browse files Browse the repository at this point in the history
  • Loading branch information
AssisrMatheus committed Sep 18, 2019
1 parent b83f273 commit 50f87f7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions components/TodoChecklister.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ local TableUtils = core.TableUtils
--------------------------------------
function TodoChecklisterFrame:AddItem(text)
if(text ~= "" and text ~= nil and text) then
if(self.selectedItem == 0) then
-- If the item is not selected

print(self.selectedItem)
if(self.selectedItem == nil or self.selectedItem == 0) then
-- Adds
table.insert(TodoChecklisterDB, #TodoChecklisterDB+1, { text=text, isChecked=false })
else
-- if editing
if (TodoChecklisterDB and TodoChecklisterDB[self.selectedItem]) then
TodoChecklisterDB[self.selectedItem].text = text
end
Expand All @@ -34,12 +39,11 @@ function TodoChecklisterFrame:RemoveItem(text)
if (self.selectedItem == indexToRemove) then
-- Clear selection
self:ClearSelected()
TodoChecklister.TodoText:ClearFocus()
end

local selectedText
-- If we have something selected, we have to re-find its index after deletion
if(self.selectedItem > 0) then
if(self.selectedItem and self.selectedItem > 0) then
-- So we store the current text
selectedText = TodoChecklisterDB[self.selectedItem].text
end
Expand Down Expand Up @@ -80,6 +84,7 @@ end
function TodoChecklisterFrame:ClearSelected()
self.selectedItem = 0
self.frame.TodoText:SetText("")
self.frame.TodoText:ClearFocus()
end

function TodoChecklisterFrame:Toggle()
Expand Down Expand Up @@ -189,7 +194,7 @@ function OnSaveItem(frame)

TodoChecklisterFrame:AddItem(text)
TodoChecklister.TodoText:SetText("")
-- TodoChecklister.TodoText:ClearFocus()
TodoChecklister.TodoText:ClearFocus()
end

function OnRemoveItem(frame)
Expand Down

0 comments on commit 50f87f7

Please sign in to comment.