···3232 local rn = vim.v.event.regname
33333434 -- check changes wwere made to default register
3535- if vim.v.event.regname == '' then
3535+ if vim.v.event.regname == "" then
3636 local yanked_text = vim.fn.getreg(rn)
37373838 -- NOTE: this only blocks adding to list if something else is in plus register
3939 if string.len(yanked_text) <= 1 then
4040- return
4040+ return
4141 end
42424343 M.add_yank(yanks, yanked_text, max_entries)
+11-4
lua/yankbank/data.lua
···15151616 -- remove trailing newlines
1717 yank = yank:gsub("\n$", "")
1818- local yank_lines = vim.split(yank, "\n", { plain= true })
1818+ local yank_lines = vim.split(yank, "\n", { plain = true })
1919 local leading_space, leading_space_length
20202121 -- determine the number of leading whitespaces on the first line
···2727 for j, line in ipairs(yank_lines) do
2828 if j == 1 then
2929 -- Format the line number with uniform spacing
3030- local lineNumber = string.format("%" .. max_digits .. "d: ", yank_num)
3030+ local lineNumber =
3131+ string.format("%" .. max_digits .. "d: ", yank_num)
3132 line = line:sub(leading_space_length + 1)
3233 table.insert(display_lines, lineNumber .. line)
3334 else
3435 -- Remove the same amount of leading whitespace as on the first line
3536 line = line:sub(leading_space_length + 1)
3637 -- Use spaces equal to the line number's reserved space to align subsequent lines
3737- table.insert(display_lines, string.rep(" ", max_digits + 2) .. line)
3838+ table.insert(
3939+ display_lines,
4040+ string.rep(" ", max_digits + 2) .. line
4141+ )
3842 end
3943 table.insert(line_yank_map, i)
4044 end
···4246 if i < #yanks then
4347 -- Add a visual separator between yanks, aligned with the yank content
4448 if sep ~= "" then
4545- table.insert(display_lines, string.rep(" ", max_digits + 2) .. sep)
4949+ table.insert(
5050+ display_lines,
5151+ string.rep(" ", max_digits + 2) .. sep
5252+ )
4653 end
4754 table.insert(line_yank_map, false)
4855 end
+2-3
lua/yankbank/helpers.lua
···1414 jumps_made = jumps_made + 1
1515 last_entry = i
1616 if jumps_made == steps then
1717- vim.api.nvim_win_set_cursor(0, {i, 0})
1717+ vim.api.nvim_win_set_cursor(0, { i, 0 })
1818 return
1919 end
2020 end
···2222 -- if steps exceeds number of entries below, jump to last entry
2323 vim.api.nvim_win_set_cursor(0, { last_entry, 0 })
2424end
2525-26252726-- navigate to the previous numbered item
2827function M.prev_numbered_item(steps)
···3433 if line:match("^%s*%d+:") and jumps_made < steps then
3534 jumps_made = jumps_made + 1
3635 if jumps_made == steps then
3737- vim.api.nvim_win_set_cursor(0, {i, 0})
3636+ vim.api.nvim_win_set_cursor(0, { i, 0 })
3837 return
3938 end
4039 end
+2-1
lua/yankbank/init.lua
···2020 local sep_opt = opts.sep or sep
2121 opts.keymaps = opts.keymaps or {}
22222323- local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt)
2323+ local bufnr, display_lines, line_yank_map =
2424+ menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt)
2425 -- handle empty bank case
2526 if not bufnr then
2627 return
+28-14
lua/yankbank/menu.lua
···1010function M.create_and_fill_buffer(yanks, 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('+')
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)
···5252 -- define buffer window width and height based on number of columns
5353 -- FIX: long enough entries will cause window to go below end of screen
5454 -- FIX: wrapping long lines will cause entries below to not show in menu (requires scrolling to see)
5555- local width = math.min(max_width + 4, vim.api.nvim_get_option_value("columns", {}))
5656- local height = math.min(display_lines and #display_lines or 1, vim.api.nvim_get_option_value("lines", {}))
5555+ local width =
5656+ math.min(max_width + 4, vim.api.nvim_get_option_value("columns", {}))
5757+ local height = math.min(
5858+ display_lines and #display_lines or 1,
5959+ vim.api.nvim_get_option_value("lines", {})
6060+ )
57615862 -- open window
5963 local win_id = vim.api.nvim_open_win(bufnr, true, {
6064 relative = "editor",
6165 width = width,
6266 height = height,
6363- col = math.floor((vim.api.nvim_get_option_value("columns", {}) - width) / 2),
6464- row = math.floor((vim.api.nvim_get_option_value("lines", {}) - height) / 2),
6767+ col = math.floor(
6868+ (vim.api.nvim_get_option_value("columns", {}) - width) / 2
6969+ ),
7070+ row = math.floor(
7171+ (vim.api.nvim_get_option_value("lines", {}) - height) / 2
7272+ ),
6573 border = "rounded",
6674 style = "minimal",
6775 })
68766977 -- Highlight current line
7070- vim.api.nvim_set_option_value('cursorline', true, { win = win_id })
7878+ vim.api.nvim_set_option_value("cursorline", true, { win = win_id })
71797280 return win_id
7381end
···105113 return ""
106114 end, { noremap = true, silent = true, buffer = bufnr })
107115 else
108108- vim.keymap.set("n", k.navigation_next, helpers.next_numbered_item,
109109- { noremap = true, silent = true, buffer = bufnr })
110110- vim.keymap.set("n", k.navigation_prev, helpers.prev_numbered_item,
111111- { noremap = true, silent = true, buffer = bufnr })
116116+ vim.keymap.set(
117117+ "n",
118118+ k.navigation_next,
119119+ helpers.next_numbered_item,
120120+ { noremap = true, silent = true, buffer = bufnr }
121121+ )
122122+ vim.keymap.set(
123123+ "n",
124124+ k.navigation_prev,
125125+ helpers.prev_numbered_item,
126126+ { noremap = true, silent = true, buffer = bufnr }
127127+ )
112128 end
113129114130 -- Map number keys to jump to entry if num_behavior is 'jump'
···125141 end
126142 end
127143 if target_line then
128128- vim.api.nvim_win_set_cursor(win_id, {target_line, 0})
144144+ vim.api.nvim_win_set_cursor(win_id, { target_line, 0 })
129145 end
130146 end, map_opts)
131147 end
132148 end
133133-134149135150 -- bind paste behavior
136151 vim.keymap.set("n", k.paste, function()
···156171 if yankIndex then
157172 local text = yanks[yankIndex]
158173 -- NOTE: possibly change this to '"' if not using system clipboard
159159- vim.fn.setreg('+', text)
174174+ vim.fn.setreg("+", text)
160175 vim.api.nvim_win_close(win_id, true)
161176 end
162177 end, { buffer = bufnr })
···167182 vim.api.nvim_win_close(win_id, true)
168183 end, map_opts)
169184 end
170170-171185end
172186173187return M