From 726031a71a7aff75c112221065bad46ea53ce3d3 Mon Sep 17 00:00:00 2001 From: ushmz <44394399+ushmz@users.noreply.github.com> Date: Sat, 13 Dec 2025 23:32:37 +0900 Subject: [PATCH 1/3] fix: ensure default session is always created and saved Modified get_or_create_default() to always create a session with id="default" and name="default" when the default session doesn't exist, and properly save it to storage backend. Previously, the fallback session object was created inline but never persisted, which could lead to inconsistent behavior. --- lua/tabi/session.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lua/tabi/session.lua b/lua/tabi/session.lua index 02809a9..9e12836 100644 --- a/lua/tabi/session.lua +++ b/lua/tabi/session.lua @@ -92,16 +92,23 @@ function M.get_or_create_default() return session end - return M.create(nil) - or { - id = DEFAULT_SESSION_ID, - name = "default", - created_at = utils.timestamp(), - updated_at = utils.timestamp(), - branch = utils.get_git_branch(), - tag = nil, - notes = {}, - } + -- Create default session with fixed ID and name + local default_session = { + id = DEFAULT_SESSION_ID, + name = "default", + created_at = utils.timestamp(), + updated_at = utils.timestamp(), + branch = utils.get_git_branch(), + tag = nil, + notes = {}, + } + + local backend = storage.get_backend() + if backend and backend.save_session then + backend.save_session(default_session) + end + + return default_session end --- List all sessions From 05f8dbc00985ecbae7e2f0b62eb3ba7a87e5a5d1 Mon Sep 17 00:00:00 2001 From: ushmz <44394399+ushmz@users.noreply.github.com> Date: Sat, 13 Dec 2025 23:32:59 +0900 Subject: [PATCH 2/3] fix: use get_or_create_default() in note delete command Changed note delete command to use get_or_create_default() instead of directly loading "default" session, making it consistent with note create and note edit commands. This ensures that when no session is active, all note commands (create/edit/delete) use the same default session logic. --- plugin/tabi.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plugin/tabi.lua b/plugin/tabi.lua index 86bf7b7..aea2251 100644 --- a/plugin/tabi.lua +++ b/plugin/tabi.lua @@ -215,12 +215,8 @@ function commands.note_delete() elseif tabi.state.current_session then session = session_module.load(tabi.state.current_session) else - session = session_module.load("default") - end - - if not session then - vim.notify("Tabi: No session found", vim.log.levels.WARN) - return + session = session_module.get_or_create_default() + tabi.state.current_session = session.id end local note = session_module.get_note_at_line(session, file_path, line) From f37d061f12f64083e9206725766c4622464cbac5 Mon Sep 17 00:00:00 2001 From: ushmz <44394399+ushmz@users.noreply.github.com> Date: Sat, 13 Dec 2025 23:50:58 +0900 Subject: [PATCH 3/3] refactor: extract session determination logic for note operations Introduced get_session_for_note_operation() helper function to centralize the logic for determining which session to use (retrace, current, or default) for note operations. This eliminates code duplication across note, note_edit, and note_delete commands, making the session selection logic consistent and easier to maintain. --- plugin/tabi.lua | 70 ++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/plugin/tabi.lua b/plugin/tabi.lua index aea2251..5bb741a 100644 --- a/plugin/tabi.lua +++ b/plugin/tabi.lua @@ -21,6 +21,31 @@ display.init() -- Command implementations local commands = {} +--- Get the appropriate session for note operations +--- Considers retrace mode, current session, and creates default if needed +---@return SessionData +local function get_session_for_note_operation() + local session + + -- If in retrace mode, use the retrace session + if retrace.is_active() then + local retrace_state = retrace.get_state() + if retrace_state then + session = retrace_state.session + end + elseif tabi.state.current_session then + session = session_module.load(tabi.state.current_session) + end + + if not session then + session = session_module.get_or_create_default() + tabi.state.current_session = session.id + display.setup_autocmds(session) + end + + return session +end + --- Start a new session function commands.start_session(args) local session_name = args[2] @@ -106,22 +131,7 @@ function commands.note(args, range_start, range_end) end -- Get or create session - local session - -- If in retrace mode, use the retrace session - if retrace.is_active() then - local retrace_state = retrace.get_state() - if retrace_state then - session = retrace_state.session - end - elseif tabi.state.current_session then - session = session_module.load(tabi.state.current_session) - end - - if not session then - session = session_module.get_or_create_default() - tabi.state.current_session = session.id - display.setup_autocmds(session) - end + local session = get_session_for_note_operation() -- Check if note already exists at this line local existing_note = session_module.get_note_at_line(session, file_path, line) @@ -161,19 +171,7 @@ function commands.note_edit() local cursor = vim.api.nvim_win_get_cursor(0) local line = cursor[1] - local session - -- If in retrace mode, use the retrace session - if retrace.is_active() then - local retrace_state = retrace.get_state() - if retrace_state then - session = retrace_state.session - end - elseif tabi.state.current_session then - session = session_module.load(tabi.state.current_session) - else - session = session_module.get_or_create_default() - tabi.state.current_session = session.id - end + local session = get_session_for_note_operation() local note = session_module.get_note_at_line(session, file_path, line) if not note then @@ -205,19 +203,7 @@ function commands.note_delete() local cursor = vim.api.nvim_win_get_cursor(0) local line = cursor[1] - local session - -- If in retrace mode, use the retrace session - if retrace.is_active() then - local retrace_state = retrace.get_state() - if retrace_state then - session = retrace_state.session - end - elseif tabi.state.current_session then - session = session_module.load(tabi.state.current_session) - else - session = session_module.get_or_create_default() - tabi.state.current_session = session.id - end + local session = get_session_for_note_operation() local note = session_module.get_note_at_line(session, file_path, line) if not note then