diff --git a/README.md b/README.md index 184a7b6..bb803f8 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,14 @@ require("dapui").setup({ repl = "r", toggle = "t", }, + -- Use this to override mappings for specific elements + element_mappings = { + -- Example: + -- stacks = { + -- open = "", + -- expand = "o", + -- } + }, -- Expand lines larger than the window -- Requires >= 0.7 expand_lines = vim.fn.has("nvim-0.7") == 1, diff --git a/lua/dapui/config/init.lua b/lua/dapui/config/init.lua index c83ed74..32f09f0 100644 --- a/lua/dapui/config/init.lua +++ b/lua/dapui/config/init.lua @@ -34,6 +34,7 @@ local default_config = { [M.actions.REPL] = "r", [M.actions.TOGGLE] = "t", }, + element_mappings = {}, expand_lines = vim.fn.has("nvim-0.7") == 1, layouts = { { @@ -171,6 +172,13 @@ require('dapui').setup( filled.layouts = config.layouts end filled.mappings = fill_mappings(filled.mappings) + + local element_mappings = {} + for elem, mappings in pairs(filled.element_mappings) do + element_mappings[elem] = fill_mappings(mappings) + end + + filled.element_mappings = element_mappings filled.floating.mappings = fill_mappings(filled.floating.mappings) for i, layout in ipairs(filled.layouts) do filled.layouts[i] = fill_elements(layout) @@ -216,6 +224,11 @@ function M.expand_lines() return user_config.expand_lines end +function M.element_mapping(element, action) + return (user_config.element_mappings[element] and user_config.element_mappings[element][action]) + or user_config.mappings[action] +end + setmetatable(M, { __index = function(_, key) return user_config[key] diff --git a/lua/dapui/render/canvas.lua b/lua/dapui/render/canvas.lua index 5e73cd7..91bcf3f 100644 --- a/lua/dapui/render/canvas.lua +++ b/lua/dapui/render/canvas.lua @@ -138,7 +138,7 @@ end ---Apply a render.canvas to a buffer ---@param state dapui.Canvas ---@param buffer number -function M.render_buffer(state, buffer) +function M.render_buffer(state, buffer, element) local success, _ = pcall(api.nvim_buf_set_option, buffer, "modifiable", true) if not success then return false @@ -151,7 +151,7 @@ function M.render_buffer(state, buffer) _mappings[buffer] = state.mappings for action, _ in pairs(state.mappings) do util.apply_mapping( - config.mappings()[action], + config.element_mapping(element, action), "lua require('dapui.render.canvas')._mapping('" .. action .. "')", buffer ) diff --git a/lua/dapui/render/loop.lua b/lua/dapui/render/loop.lua index 8997f6b..9a67ec8 100644 --- a/lua/dapui/render/loop.lua +++ b/lua/dapui/render/loop.lua @@ -95,6 +95,7 @@ end function M.run(element_names) element_names = get_elements(element_names) for _, elem_name in pairs(element_names) do + local elem_id = string.gsub(string.lower(elem_name), "dap ", "") local canvas_state = canvas_states[elem_name] if not vim.tbl_isempty(canvas_state.buffers) then local canvas = Canvas.new() @@ -102,7 +103,7 @@ function M.run(element_names) canvas_state.element.render(canvas) if canvas.valid then for _, buf in pairs(canvas_state.buffers) do - local rendered = Canvas.render_buffer(canvas, buf) + local rendered = Canvas.render_buffer(canvas, buf, elem_id) if rendered then for _, listener in pairs(canvas_state.listeners[M.EVENTS.RENDER] or {}) do listener(buf, canvas)