diff --git a/frontend/readhistory.lua b/frontend/readhistory.lua index 41c4c288b..31ce10280 100644 --- a/frontend/readhistory.lua +++ b/frontend/readhistory.lua @@ -200,7 +200,7 @@ function ReadHistory:clearMissing() assert(self ~= nil) for i = #self.hist, 1, -1 do if self.hist[i].file == nil or lfs.attributes(self.hist[i].file, "mode") ~= "file" then - table.remove(self.hist, i) + self:removeItem(self.hist[i], i) end end self:ensureLastFile() @@ -237,11 +237,11 @@ function ReadHistory:updateItemByPath(old_path, new_path) self:ensureLastFile() end -function ReadHistory:removeItem(item) +function ReadHistory:removeItem(item, idx) assert(self ~= nil) - table.remove(self.hist, item.index) + table.remove(self.hist, item.index or idx) os.remove(DocSettings:getHistoryPath(item.file)) - self:_indexing(item.index) + self:_indexing(item.index or idx) self:_flush() self:ensureLastFile() end diff --git a/spec/unit/readhistory_spec.lua b/spec/unit/readhistory_spec.lua index 1dedd6bab..e1a62c71b 100644 --- a/spec/unit/readhistory_spec.lua +++ b/spec/unit/readhistory_spec.lua @@ -37,13 +37,13 @@ describe("ReadHistory module", function() end local function assert_item_is(h, i, name, fileRemoved) - assert.is.same(h.hist[i].text, name) - assert.is.same(h.hist[i].index, i) - assert.is.same(h.hist[i].file, joinPath(realpath(test_data_dir()), name)) + assert.is.same(name, h.hist[i].text) + assert.is.same(i, h.hist[i].index) + assert.is.same(joinPath(realpath(test_data_dir()), name), h.hist[i].file) if fileRemoved then assert.is_nil(realpath(test_file(name))) else - assert.is.same(h.hist[i].file, realpath(test_file(name))) + assert.is.same(realpath(test_file(name)), h.hist[i].file) end end