Skip to content

Commit cf06962

Browse files
committed
feat: correctly handle multiple simultaneous sessions with db
1 parent 59cd263 commit cf06962

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lua/yankbank/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ local default_opts = {
2424

2525
--- wrapper function for main plugin functionality
2626
---@param opts table
27-
--- TODO: read from persistent database if sql persist is set (allow multi-session sync)
2827
local function show_yank_bank(opts)
28+
yanks = persistence.get_yanks(opts) or yanks
29+
2930
-- initialize buffer and populate bank
3031
local bufnr, display_lines, line_yank_map =
3132
menu.create_and_fill_buffer(yanks, reg_types, opts)

lua/yankbank/persistence.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ function M.add_entry(entry, reg_type, opts)
1212
end
1313
end
1414

15+
--- get current state of yanks in persistent storage
16+
---@param opts table
17+
function M.get_yanks(opts)
18+
if opts.persist_type == "sqlite" then
19+
return persistence:get_bank()
20+
end
21+
end
22+
1523
---initialize bank persistence
1624
---@param opts table
1725
---@return table

lua/yankbank/persistence/sql.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ function data:get_bank()
8282
return yanks, reg_types
8383
end
8484

85-
-- FIX: correctly handle multiple sessions open at once
86-
8785
--- set up database persistence
8886
---@param opts table
8987
---@return sqlite_tbl data

0 commit comments

Comments
 (0)