diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index 7f4b37f9e..881d5e195 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -95,7 +95,6 @@ function ReaderDictionary:stardictLookup(word, box) definition = _("No definition found."), } } - DEBUG("dummy result table:", word, results) self:showDict(word, results, box) end end @@ -103,7 +102,7 @@ end function ReaderDictionary:showDict(word, results, box) if results and results[1] then - DEBUG("showing quick lookup window") + DEBUG("showing quick lookup window", word, results) self.dict_window = DictQuickLookup:new{ ui = self.ui, highlight = self.highlight, diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 7d7e994d1..6e0e2bf97 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -182,10 +182,13 @@ function UIManager:close(widget, refreshtype, refreshregion) end dbg("close widget", widget.id) local dirty = false + -- first send close event to widget + widget:handleEvent(Event:new("CloseWidget")) + -- then remove all reference to that widget on stack and update + -- disable_double_tap accordingly + Input.disable_double_tap = false for i = #self._window_stack, 1, -1 do if self._window_stack[i].widget == widget then - -- tell the widget that it is closed now - widget:handleEvent(Event:new("CloseWidget")) table.remove(self._window_stack, i) dirty = true elseif self._window_stack[i].widget.disable_double_tap then @@ -315,7 +318,7 @@ end dbg:guard(UIManager, 'setDirty', nil, function(self, widget, refreshtype, refreshregion) - if not widget then return end + if not widget or widget == "all" then return end -- when debugging, we check if we get handed a valid widget, -- which would be a dialog that was previously passed via show() local found = false @@ -562,9 +565,8 @@ function UIManager:_repaint() end self._refresh_func_stack = {} - -- we should have at least one refresh if we did repaint. - -- If we don't, we add one now and print a warning if we - -- are debugging + -- we should have at least one refresh if we did repaint. If we don't, we + -- add one now and log a warning if we are debugging if dirty and #self._refresh_stack == 0 then dbg("WARNING: no refresh got enqueued. Will do a partial full screen refresh, which might be inefficient") self:_refresh("partial") diff --git a/spec/unit/uimanager_spec.lua b/spec/unit/uimanager_spec.lua index a8dd67832..c0d011a7d 100644 --- a/spec/unit/uimanager_spec.lua +++ b/spec/unit/uimanager_spec.lua @@ -345,4 +345,23 @@ describe("UIManager spec", function() UIManager:broadcastEvent("foo") assert.is.same(#UIManager._window_stack, 0) end) + + it("should handle stack change when closing widgets", function() + local widget_1 = {handleEvent = function()end} + local widget_2 = { + handleEvent = function() + UIManager:close(widget_1) + end + } + local widget_3 = {handleEvent = function()end} + UIManager._window_stack = { + {widget = widget_1}, + {widget = widget_2}, + {widget = widget_3}, + } + UIManager:close(widget_2) + + assert.is.same(1, #UIManager._window_stack) + assert.is.same(widget_3, UIManager._window_stack[1].widget) + end) end)