@@ -18,6 +18,9 @@ local state = {
1818 display_order = {}, -- Display order including both working and deleted buffers (for UI)
1919 history = {}, -- History for undo/redo
2020 history_index = 0 , -- Current position in history
21+ -- Volatile (in-memory) persistence used when kikao.nvim is not available.
22+ -- Stores buffer paths in the same shape that kikao would.
23+ persisted_order_paths = {},
2124}
2225
2326--- Returns a valid sorting string
@@ -68,7 +71,16 @@ local function get_persisted_data(sorting)
6871 -- check if plugin kikao.nvim is installed
6972 -- and if so, get the persisted order from its storage
7073 local kikao_ok , kikao_api = pcall (require , " kikao.api" )
71- if not kikao_ok then return { buffers = {}, sorting = get_valid_sorting (sorting ) } end
74+ if not kikao_ok then
75+ -- Fall back to volatile (in-memory) persistence.
76+ -- Use current in-memory sorting if available, otherwise the provided one.
77+ local effective_sorting = sorting or state .sorting
78+ effective_sorting = get_valid_sorting (effective_sorting )
79+ return {
80+ buffers = state .persisted_order_paths or {},
81+ sorting = effective_sorting ,
82+ }
83+ end
7284 --- @type BafaBuffer[] | nil
7385 local ordered_buffers = kikao_api .get_value ({ key = " plugins.bafa.buffers" }) or {}
7486 --- @type BafaSorting
@@ -557,6 +569,9 @@ function M.save_order()
557569 if should_save then table.insert (ordererd_buffers , buf .path ) end
558570 end
559571 end
572+ -- Always keep a volatile copy in memory so that order persists
573+ -- for the lifetime of the Neovim session even without kikao.nvim.
574+ state .persisted_order_paths = ordererd_buffers
560575 -- check if plugin kikao.nvim is installed
561576 -- and if so, save the persisted order to its storage
562577 local kikao_ok , kikao_api = pcall (require , " kikao.api" )
@@ -578,6 +593,9 @@ function M.get_persisted_sorting()
578593 local kikao_ok , kikao_api = pcall (require , " kikao.api" )
579594 if not kikao_ok then
580595 Logger .warn (" kikao.nvim not found, returning from volatile state (in-memory) or DEFAULT" , " See: " .. KIKAO_URL )
596+ -- When kikao.nvim is not available, rely on in-memory state
597+ -- so sorting mode persists for the duration of the Neovim session.
598+ if state .sorting ~= nil then return get_valid_sorting (state .sorting ) end
581599 return Types .BafaSorting .DEFAULT
582600 end
583601 local sorting = kikao_api .get_value ({ key = " plugins.bafa.sorting" })
0 commit comments