From b0b71414e720d941632817ebc54db6fd50ded25f Mon Sep 17 00:00:00 2001 From: AssisrMatheus Date: Mon, 16 Sep 2019 22:46:11 -0300 Subject: [PATCH] :bug: #3: Fixed a bug while deleting a not selected item --- components/TodoChecklister.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/TodoChecklister.lua b/components/TodoChecklister.lua index 8f74ba5..1ce7b34 100644 --- a/components/TodoChecklister.lua +++ b/components/TodoChecklister.lua @@ -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