Neovim plugin improving access to clipboard history (mirror)

feat: Add a snacks picker integration

authored by

Arne Van Maele and committed by
GitHub
82b0c584 31e2cbe7

+74 -1
+12
README.md
··· 115 115 | persist_type | string defining persistence type "sqlite" or nil | `nil` | 116 116 | db_path | string defining database file path for use with sqlite persistence | plugin install directory | 117 117 | bind_indices | optional string to be used for keybind prefix for pasting by index number (i.e. "<leader>p") | `nil` | 118 + | pickers | table containing all pickers. | `{}` | 119 + | pickers.snacks | boolean | `false` | 118 120 119 121 120 122 #### Example Configuration ··· 122 124 ```lua 123 125 { 124 126 "ptdewey/yankbank-nvim", 127 + dependencies = { 128 + "folke/snacks.nvim", -- (optional) - snacks picker integration 129 + }, 125 130 config = function() 126 131 require('yankbank').setup({ 127 132 max_entries = 9, ··· 137 142 yank_register = "+", 138 143 }, 139 144 bind_indices = "<leader>p" 145 + pickers = { 146 + snacks = true, 147 + }, 140 148 }) 141 149 end, 142 150 } ··· 187 195 -- map to '<leader>y' 188 196 vim.keymap.set("n", "<leader>y", "<cmd>YankBank<CR>", { noremap = true }) 189 197 ``` 198 + 199 + ### Snacks Picker 200 + If `pickers.snacks` is set to true in the setup options, the snacks picker can be used to open the yankbank menu. 201 + This can be triggered by running the command `:YankBankSnacks` or using `Snacks.picker.yankbank()` as you would any other snacks picker. 190 202 191 203 --- 192 204
+5 -1
lua/yankbank/init.lua
··· 13 13 -- enable persistence based on opts (needs to be called before autocmd setup) 14 14 local yanks, reg_types, pins = persistence.setup() 15 15 state.init(yanks, reg_types, pins, state.get_opts()) 16 - 17 16 initialized = true 18 17 end 19 18 ··· 60 59 persist_type = nil, 61 60 db_path = nil, 62 61 bind_indices = nil, 62 + pickers = {}, 63 63 } 64 64 65 65 -- merge opts with default options table ··· 93 93 desc = "Paste YankBank entry " .. i, 94 94 }) 95 95 end 96 + end 97 + 98 + if merged_opts.pickers.snacks then 99 + require("yankbank.pickers.snacks").setup() 96 100 end 97 101 end 98 102
+57
lua/yankbank/pickers/snacks.lua
··· 1 + -- luacheck: globals Snacks 2 + local M = {} 3 + 4 + ---@type snacks.picker.Config 5 + local snacks_source = { 6 + title = "YankBank", 7 + finder = function() 8 + local yanks = require("yankbank.api").get_all() 9 + local items = {} 10 + for i = 1, #yanks do 11 + local yank = yanks[i] 12 + local yank_text = yank.yank_text 13 + table.insert(items, { 14 + label = tostring(i), 15 + reg = tostring(i), 16 + -- This is not used right now, but might be useful in the future 17 + -- to determine how to paste the content 18 + reg_type = yank.reg_type, 19 + -- data is used as the paste content 20 + data = yank_text, 21 + -- text is used by the matcher for searching 22 + text = yank_text, 23 + -- value is used to display in the picker 24 + value = yank_text, 25 + preview = { 26 + text = yank_text, 27 + -- Currently this is pinned to the current buffer's filetype 28 + -- as we don't store the filetype of each yank. 29 + -- This should be sufficient, as you would usually want to 30 + -- paste into the same filetype you yanked from. 31 + ft = vim.bo.filetype, 32 + }, 33 + }) 34 + end 35 + return items 36 + end, 37 + format = "register", 38 + preview = "preview", 39 + confirm = { "paste", "close" }, 40 + } 41 + 42 + function M.setup() 43 + if Snacks and Snacks.picker then 44 + Snacks.picker.sources.yankbank = snacks_source 45 + end 46 + vim.api.nvim_create_user_command("YankBankSnacks", function() 47 + if Snacks then 48 + Snacks.picker(snacks_source) 49 + else 50 + vim.notify("Yank bank: Snacks is not loaded", vim.log.levels.ERROR) 51 + end 52 + end, { 53 + desc = "Open yankbank in snacks picker", 54 + }) 55 + end 56 + 57 + return M