Skip to content

Commit e588658

Browse files
authored
fix(state): persist manual sort store when kikao.nvim is not available (#55)
Also fix multiple notifications, when sorting changes.
1 parent 7e3cbd5 commit e588658

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ See: [lazy.nvim](https://github.com/folke/lazy.nvim)
7878
```lua
7979
{
8080
'mistweaverco/bafa.nvim',
81-
version = 'v1.11.0',
81+
version = 'v1.11.1',
8282
},
8383
```
8484

@@ -89,7 +89,7 @@ See: [packer.nvim](https://github.com/wbthomason/packer.nvim)
8989
```lua
9090
use {
9191
'mistweaverco/bafa.nvim',
92-
tag = 'v1.11.0',
92+
tag = 'v1.11.1',
9393
})
9494
```
9595

@@ -98,7 +98,7 @@ use {
9898
```lua
9999
vim.pack.add({
100100
src = 'https://github.com/mistweaverco/bafa.nvim.git',
101-
version = 'v1.11.0',
101+
version = 'v1.11.1',
102102
})
103103
require('bafa').setup()
104104
```

lua/bafa/utils/state.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)