feat: implement mode_manager plugin with enhanced state management
Signed-off-by: juliano.barbosa <julianomb@gmail.com>
This commit is contained in:
parent
f8b3501df1
commit
94cd09806e
5 changed files with 68 additions and 80 deletions
|
|
@ -7,4 +7,14 @@ return {
|
|||
{ 'folke/trouble.nvim', event = 'VimEnter', dependencies = { 'nvim-tree/nvim-web-devicons' }, config = function()
|
||||
require('trouble').setup {}
|
||||
end },
|
||||
|
||||
-- Mode Manager Plugin (local)
|
||||
{
|
||||
dir = vim.fn.stdpath('config') .. '/lua/custom/plugins/mode_manager',
|
||||
name = 'mode_manager',
|
||||
event = 'VimEnter',
|
||||
config = function()
|
||||
require('custom.plugins.mode_manager').setup()
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,15 +94,12 @@ end
|
|||
local function restore_context(mode)
|
||||
local ctx = M.state.contexts[mode]
|
||||
if ctx then
|
||||
-- Restore window view
|
||||
if ctx.window then
|
||||
vim.fn.winrestview(ctx.window)
|
||||
end
|
||||
-- Restore cursor position
|
||||
if ctx.cursor then
|
||||
vim.api.nvim_win_set_cursor(0, ctx.cursor)
|
||||
end
|
||||
-- Restore folding
|
||||
if ctx.folding then
|
||||
vim.wo.foldenable = true
|
||||
vim.wo.foldmethod = ctx.folding
|
||||
|
|
@ -207,7 +204,7 @@ function M.save_state()
|
|||
settings = M.state.settings,
|
||||
contexts = M.state.contexts,
|
||||
last_updated = os.time(),
|
||||
version = '1.0' -- Added versioning
|
||||
version = '1.0'
|
||||
}
|
||||
file:write(vim.fn.json_encode(persist_state))
|
||||
file:close()
|
||||
|
|
@ -224,13 +221,11 @@ function M.load_state()
|
|||
if content and content ~= '' then
|
||||
local decoded = vim.fn.json_decode(content)
|
||||
if decoded then
|
||||
-- Restore state with validation
|
||||
if decoded.version == '1.0' then
|
||||
M.state.current_mode = decoded.current_mode
|
||||
M.state.settings = decoded.settings or {act = {}, plan = {}}
|
||||
M.state.contexts = decoded.contexts or {act = {}, plan = {}}
|
||||
else
|
||||
-- Handle older versions or invalid state
|
||||
M.state.current_mode = decoded.current_mode or 'act'
|
||||
M.state.settings = {act = {}, plan = {}}
|
||||
M.state.contexts = {act = {}, plan = {}}
|
||||
|
|
@ -250,6 +245,16 @@ function M.load_state()
|
|||
end
|
||||
end
|
||||
|
||||
-- Get mode history
|
||||
function M.get_history()
|
||||
return M.state.history
|
||||
end
|
||||
|
||||
-- Clear mode history
|
||||
function M.clear_history()
|
||||
M.state.history = {}
|
||||
end
|
||||
|
||||
-- Initialize the plugin
|
||||
function M.setup()
|
||||
-- Load saved state
|
||||
|
|
@ -272,14 +277,4 @@ function M.setup()
|
|||
end)
|
||||
end
|
||||
|
||||
-- Get mode history
|
||||
function M.get_history()
|
||||
return M.state.history
|
||||
end
|
||||
|
||||
-- Clear mode history
|
||||
function M.clear_history()
|
||||
M.state.history = {}
|
||||
end
|
||||
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue