Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.62.2
2.63.0
35 changes: 35 additions & 0 deletions lua/codediff/keymap/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Keymap registry facade.
--
-- Every codediff mapping is installed through a per-session registry, which
-- records exactly what it installed and what was there before, so teardown can
-- hand the key back to its previous owner instead of deleting it.
--
-- See codediff.keymap.slots for the ownership rules.

local M = {}

local registry = require("codediff.keymap.registry")
local slots = require("codediff.keymap.slots")
local normalize = require("codediff.keymap.normalize")

--- Create a registry for one session.
--- @param name string Diagnostic label
--- @return table
function M.new(name)
return registry.new(name)
end

--- Forget every slot for a wiped buffer without touching Neovim.
--- @param bufnr number
function M.forget_buffer(bufnr)
slots.forget_buffer(bufnr)
end

M.canonical = normalize.canonical
M.resolve = normalize.resolve

--- Live slot count. Test/diagnostic helper.
M.slot_count = slots.count
M.inspect_slot = slots.inspect

return M
46 changes: 46 additions & 0 deletions lua/codediff/keymap/normalize.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Key-sequence normalization for the keymap registry.
--
-- Mapping identity must be canonical: `<Tab>` and `<C-i>` are the same key to
-- Neovim, and `<leader>x` depends on the value of `mapleader` at the moment
-- the mapping is created. Slots are therefore keyed by the fully expanded
-- byte sequence, computed once at claim time and stored, never recomputed.

local M = {}

--- Expand a key sequence to its canonical byte form.
--- @param lhs string
--- @return string|nil canonical nil when lhs is not a usable key sequence
function M.canonical(lhs)
if type(lhs) ~= "string" or lhs == "" then
return nil
end
local ok, expanded = pcall(vim.api.nvim_replace_termcodes, lhs, true, true, true)
if not ok or expanded == "" then
return nil
end
return expanded
end

--- Resolve a configured binding value to a key sequence.
--- Preserves the existing contract: a string binds, `false` (or nil, or an
--- empty string) silently disables. No other shape is accepted.
--- @param value string|false|nil
--- @return string|nil lhs
function M.resolve(value)
if type(value) ~= "string" or value == "" then
return nil
end
return value
end

--- Normalize a mode argument to a list of single-character modes.
--- @param modes string|string[]
--- @return string[]
function M.modes(modes)
if type(modes) == "table" then
return modes
end
return { modes }
end

return M
Loading
Loading