···1111---@param opts table
1212function M.add_yank(yanks, reg_types, text, reg_type, opts)
1313 -- avoid adding empty strings
1414- -- TODO: could block adding single characters here
1515- if text == "" or text == " " or text == "\n" then
1414+ if text == "" and text == " " and text == "\n" then
1615 return
1716 end
18171919- -- do not update with duplicate values
2020- for _, entry in ipairs(yanks) do
1818+ -- check for duplicate values already inserted
1919+ for i, entry in ipairs(yanks) do
2120 if entry == text then
2222- return
2121+ -- remove matched entry so it can be inserted at 1st position
2222+ table.remove(yanks, i)
2323+ table.remove(reg_types, i)
2424+ break
2325 end
2426 end
25272628 -- add entry to bank
2729 table.insert(yanks, 1, text)
2830 table.insert(reg_types, 1, reg_type)
3131+3232+ -- trim table size if necessary
2933 if #yanks > opts.max_entries then
3034 table.remove(yanks)
3135 table.remove(reg_types)
···5761 if #yank_text <= 1 then
5862 return
5963 end
6464+6065 M.add_yank(yanks, reg_types, yank_text, reg_type, opts)
6166 end
6267 end,