···22local M = {}
3344-- Function to add yanked text to table
55-function M.add_yank(yanks, text, max_entries)
55+function M.add_yank(yanks, reg_types, text, reg_type, max_entries)
66 -- avoid adding empty strings
77 if text ~= "" and text ~= " " and text ~= "\n" then
88 -- do not update with duplicate values
···1212 end
1313 end
1414 table.insert(yanks, 1, text)
1515+ table.insert(reg_types, 1, reg_type)
1516 if #yanks > max_entries then
1617 table.remove(yanks)
1818+ table.remove(reg_types)
1719 end
1820 end
1921end
20222123-- autocommand to listen for yank events
2222-function M.setup_yank_autocmd(yanks, max_entries)
2424+function M.setup_yank_autocmd(yanks, reg_types, max_entries)
2325 vim.api.nvim_create_autocmd("TextYankPost", {
2426 callback = function()
2527 -- TODO: this function can be expanded to incorporate other registers
···30323133 -- get register information
3234 local rn = vim.v.event.regname
3535+ local reg_type = vim.fn.getregtype('"')
33363437 -- check changes wwere made to default register
3538 if vim.v.event.regname == "" then
···4043 return
4144 end
42454343- M.add_yank(yanks, yanked_text, max_entries)
4646+ M.add_yank(yanks, reg_types, yanked_text, reg_type, max_entries)
4447 end
4548 end,
4649 })
+4-7
lua/yankbank/helpers.lua
···4242 vim.api.nvim_win_set_cursor(0, { 1, 0 })
4343end
44444545--- customized paste function that functions more like 'p'
4646-function M.smart_paste(text)
4545+-- customized paste function that functions like 'p'
4646+function M.smart_paste(text, reg_type)
4747 -- convert text string to string list
4848 local lines = {}
4949 for line in text:gmatch("([^\n]*)\n?") do
5050 table.insert(lines, line)
5151 end
52525353- -- determine if the text should be treated as line-wise based on its ending
5454- local type = "c"
5353+ -- remove last newline character to replicate base put behavior
5554 if #lines > 1 then
5656- type = "l"
5757- -- remove last newline character to replicate base put behavior
5855 table.remove(lines)
5956 end
6060- vim.api.nvim_put(lines, type, true, true)
5757+ vim.api.nvim_put(lines, reg_type, true, true)
6158end
62596360return M
+4-4
lua/yankbank/init.lua
···7788-- initialize yanks tables
99local yanks = {}
1010+local reg_types = {}
1011local max_entries = 10
1112local sep = "-----"
1213···2122 opts.keymaps = opts.keymaps or {}
22232324 local bufnr, display_lines, line_yank_map =
2424- menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt)
2525+ menu.create_and_fill_buffer(yanks, reg_types, max_entries_opt, sep_opt)
2526 -- handle empty bank case
2627 if not bufnr then
2728 return
2829 end
2930 local win_id = menu.open_window(bufnr, display_lines)
3030- menu.set_keymaps(win_id, bufnr, yanks, line_yank_map, opts)
3131+ menu.set_keymaps(win_id, bufnr, yanks, reg_types, line_yank_map, opts)
3132end
32333334-- plugin setup
···36373738 -- parse opts
3839 max_entries = opts.max_entries or max_entries
3939- -- sep = opts.sep or sep
40404141 -- create clipboard autocmds
4242- clipboard.setup_yank_autocmd(yanks, max_entries)
4242+ clipboard.setup_yank_autocmd(yanks, reg_types, max_entries)
43434444 -- Create user command
4545 vim.api.nvim_create_user_command("YankBank", function()
+6-4
lua/yankbank/menu.lua
···77local helpers = require("yankbank.helpers")
8899-- create new buffer and reformat yank table for ui
1010-function M.create_and_fill_buffer(yanks, max_entries, sep)
1010+function M.create_and_fill_buffer(yanks, reg_types, max_entries, sep)
1111 -- check the content of the system clipboard register
1212 -- TODO: this could be replaced with some sort of polling of the + register
1313 local text = vim.fn.getreg("+")
1414 local most_recent_yank = yanks[1] or ""
1515 if text ~= most_recent_yank then
1616- clipboard.add_yank(yanks, text, max_entries)
1616+ local reg_type = vim.fn.getregtype("+")
1717+ clipboard.add_yank(yanks, reg_types, text, reg_type, max_entries)
1718 end
18191920 -- stop if yank table is empty
···8182end
82838384-- Set key mappings for the popup window
8484-function M.set_keymaps(win_id, bufnr, yanks, line_yank_map, opts)
8585+function M.set_keymaps(win_id, bufnr, yanks, reg_types, line_yank_map, opts)
8586 -- Key mappings for selection and closing the popup
8687 local map_opts = { noremap = true, silent = true, buffer = bufnr }
8788···158159159160 -- close window upon selection
160161 vim.api.nvim_win_close(win_id, true)
161161- helpers.smart_paste(text)
162162+ helpers.smart_paste(text, reg_types[yankIndex])
162163 else
163164 print("Error: Invalid selection")
164165 end
···171172 if yankIndex then
172173 local text = yanks[yankIndex]
173174 -- NOTE: possibly change this to '"' if not using system clipboard
175175+ -- - make this an option
174176 vim.fn.setreg("+", text)
175177 vim.api.nvim_win_close(win_id, true)
176178 end