Skip to content

Commit 49b015e

Browse files
authored
fix: clear all marks not persisting changes (#17)
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
1 parent ace36b6 commit 49b015e

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lua/marksman/ui.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ local function setup_window_keymaps(buf, marks, project_name, mark_info, search_
438438
prompt = "Clear all marks in this project?",
439439
}, function(choice)
440440
if choice == "Yes" then
441-
local storage = require("marksman.storage")
442-
storage.clear_all_marks()
441+
local marksman = require("marksman")
442+
marksman.clear_all_marks()
443443
close_window()
444444
notify("󰃀 All marks cleared", vim.log.levels.INFO)
445445
end

tests/marksman_spec.lua

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,45 @@ describe("marksman.nvim", function()
155155
result = marksman.delete_mark("nonexistent")
156156
assert.is_false(result.success)
157157
end)
158+
159+
-- Test case for the clear all marks bug fix
160+
-- This ensures that clearing all marks through the UI properly persists the changes
161+
it("clears all marks and persists changes", function()
162+
vim.cmd("edit " .. test_file)
163+
164+
-- Add multiple marks at different positions
165+
marksman.add_mark("mark1")
166+
vim.fn.cursor(2, 1)
167+
marksman.add_mark("mark2")
168+
vim.fn.cursor(3, 1)
169+
marksman.add_mark("mark3")
170+
171+
-- Verify marks were added
172+
assert.equals(3, marksman.get_marks_count())
173+
174+
-- Mock vim.ui.select to automatically confirm the clear action
175+
local original_select = vim.ui.select
176+
vim.ui.select = function(choices, opts, callback)
177+
if opts.prompt == "Clear all marks in this project?" then
178+
callback("Yes") -- Simulate user selecting "Yes"
179+
end
180+
end
181+
182+
-- Clear all marks (this should trigger the save mechanism)
183+
marksman.clear_all_marks()
184+
185+
-- Restore original function
186+
vim.ui.select = original_select
187+
188+
-- Verify marks were cleared immediately
189+
assert.equals(0, marksman.get_marks_count())
190+
191+
-- Wait for any debounced save operations to complete
192+
vim.wait(200)
193+
194+
-- Verify marks remain cleared after save delay
195+
assert.equals(0, marksman.get_marks_count(), "Marks should remain cleared after debounced save")
196+
end)
158197
end)
159198

160199
describe("mark search and filtering", function()

0 commit comments

Comments
 (0)