Skip to content

Commit

Permalink
🐛 #3: Fixed a bug while deleting a not selected item
Browse files Browse the repository at this point in the history
  • Loading branch information
AssisrMatheus committed Sep 17, 2019
1 parent e6affad commit b0b7141
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions components/TodoChecklister.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,27 @@ function TodoChecklisterFrame:RemoveItem(text)
local indexToRemove = TableUtils:IndexOf(TodoChecklisterDB, function(x) return x.text == text end)

if(indexToRemove > 0) then
-- If we are removing the current selected item
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
-- So we store the current text
selectedText = TodoChecklisterDB[self.selectedItem].text
end

table.remove(TodoChecklisterDB, indexToRemove)

if(selectedText ~= nil) then
local indexToSelect = TableUtils:IndexOf(TodoChecklisterDB, function(x) return x.text == selectedText end)
self.selectedItem = indexToSelect;
end

self:OnUpdate()
end
end
Expand Down

0 comments on commit b0b7141

Please sign in to comment.