feat(picker): make register picker list more informative

This commit
- adds separate hightlighting for different register types (numbered,
  named, other)
- adds a hint about the register type (characterwise, linewise,
  blockwise) similar to the builtin :reg command
This commit is contained in:
Jakub F. Bortlík 2025-07-03 11:32:48 +02:00
parent bc0630e43b
commit 00e7380b69
3 changed files with 10 additions and 2 deletions

View file

@ -38,7 +38,9 @@ Snacks.util.set_hl({
AuGroup = "Type",
DiagnosticCode = "Special",
DiagnosticSource = "Comment",
Register = "Number",
RegisterNumber = "Number",
RegisterOther = "Constant",
RegisterString = "String",
KeymapMode = "Number",
KeymapLhs = "Special",
KeymapNowait = "@variable.builtin",

View file

@ -596,11 +596,14 @@ end
function M.register(item)
local ret = {} ---@type snacks.picker.Highlight[]
local hl = string.match(item.reg, "[0-9]") and "Number" or string.match(item.reg, "[a-z]") and "String" or "Other"
ret[#ret + 1] = { " " }
ret[#ret + 1] = { "[", "SnacksPickerDelim" }
ret[#ret + 1] = { item.reg, "SnacksPickerRegister" }
ret[#ret + 1] = { item.reg, "SnacksPickerRegister" .. hl }
ret[#ret + 1] = { "]", "SnacksPickerDelim" }
ret[#ret + 1] = { " " }
ret[#ret + 1] = { item.type, "Comment" }
ret[#ret + 1] = { " " }
ret[#ret + 1] = { item.value }
return ret
end

View file

@ -273,11 +273,14 @@ function M.registers()
value = (ok and reg_value or "") --[[@as string]]
end
if value ~= "" then
local type = vim.fn.getregtype(reg)
type = type == "v" and "c" or type == "V" and "l" or "b:" .. type:sub(2)
table.insert(items, {
text = ("%s: %s"):format(reg, value:gsub("\n", "\\n"):gsub("\r", "\\r")),
reg = reg,
label = reg,
data = value,
type = type,
value = value:gsub("\n", "\\n"):gsub("\r", "\\r"),
preview = {
text = value,