From 19f7d1d149bdd8b0cee5fe336c3ab41986832f4d Mon Sep 17 00:00:00 2001 From: alexekdahl Date: Mon, 3 Nov 2025 07:31:01 +0100 Subject: [PATCH 1/2] fix: clear all marks not persisting changes The UI was calling storage.clear_all_marks() directly which only cleared marks in memory. Now uses the main module's method to properly save changes. Solves: #16 --- lua/marksman/ui.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/marksman/ui.lua b/lua/marksman/ui.lua index a83cbeb..8fa81f8 100644 --- a/lua/marksman/ui.lua +++ b/lua/marksman/ui.lua @@ -438,8 +438,8 @@ local function setup_window_keymaps(buf, marks, project_name, mark_info, search_ prompt = "Clear all marks in this project?", }, function(choice) if choice == "Yes" then - local storage = require("marksman.storage") - storage.clear_all_marks() + local marksman = require("marksman") + marksman.clear_all_marks() close_window() notify("󰃀 All marks cleared", vim.log.levels.INFO) end From a7d175e4620f754faa41d20cc127ed7d271b23c8 Mon Sep 17 00:00:00 2001 From: alexekdahl Date: Mon, 3 Nov 2025 07:39:46 +0100 Subject: [PATCH 2/2] test: added test --- tests/marksman_spec.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/marksman_spec.lua b/tests/marksman_spec.lua index 7fde9a2..7abf745 100644 --- a/tests/marksman_spec.lua +++ b/tests/marksman_spec.lua @@ -155,6 +155,45 @@ describe("marksman.nvim", function() result = marksman.delete_mark("nonexistent") assert.is_false(result.success) end) + + -- Test case for the clear all marks bug fix + -- This ensures that clearing all marks through the UI properly persists the changes + it("clears all marks and persists changes", function() + vim.cmd("edit " .. test_file) + + -- Add multiple marks at different positions + marksman.add_mark("mark1") + vim.fn.cursor(2, 1) + marksman.add_mark("mark2") + vim.fn.cursor(3, 1) + marksman.add_mark("mark3") + + -- Verify marks were added + assert.equals(3, marksman.get_marks_count()) + + -- Mock vim.ui.select to automatically confirm the clear action + local original_select = vim.ui.select + vim.ui.select = function(choices, opts, callback) + if opts.prompt == "Clear all marks in this project?" then + callback("Yes") -- Simulate user selecting "Yes" + end + end + + -- Clear all marks (this should trigger the save mechanism) + marksman.clear_all_marks() + + -- Restore original function + vim.ui.select = original_select + + -- Verify marks were cleared immediately + assert.equals(0, marksman.get_marks_count()) + + -- Wait for any debounced save operations to complete + vim.wait(200) + + -- Verify marks remain cleared after save delay + assert.equals(0, marksman.get_marks_count(), "Marks should remain cleared after debounced save") + end) end) describe("mark search and filtering", function()