Skip to content

Commit

Permalink
feat(windows): close float mapping
Browse files Browse the repository at this point in the history
See #43
  • Loading branch information
rcarriga committed Aug 3, 2021
1 parent 70c7b52 commit 90a4025
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ require("dapui").setup({
floating = {
max_height = nil, -- These can be integers or a float between 0 and 1.
max_width = nil, -- Floats will be treated as percentage of your screen.
mappings = {
close = { "q", "<Esc>" },
},
},
windows = { indent = 1 },
})
Expand Down
8 changes: 8 additions & 0 deletions lua/dapui/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ M.actions = {
REPL = "repl",
}

M.FLOAT_MAPPINGS = {
CLOSE = "close",
}

local default_config = {
icons = { expanded = "", collapsed = "" },
mappings = {
Expand Down Expand Up @@ -52,6 +56,9 @@ local default_config = {
floating = {
max_height = nil, -- These can be integers or a float between 0 and 1.
max_width = nil, -- Floats will be treated as percentage of your screen.
mappings = {
[M.FLOAT_MAPPINGS.CLOSE] = { "q", "<Esc>" },
},
},
windows = { indent = 1 },
}
Expand Down Expand Up @@ -83,6 +90,7 @@ end
function M.setup(config)
local filled = vim.tbl_deep_extend("keep", config or {}, default_config)
filled.mappings = fill_mappings(filled.mappings)
filled.floating.mappings = fill_mappings(filled.floating.mappings)
filled.sidebar = fill_elements(filled.sidebar)
filled.tray = fill_elements(filled.tray)
user_config = filled
Expand Down
2 changes: 1 addition & 1 deletion lua/dapui/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ end

function M.apply_mapping(mappings, func, buffer)
for _, key in pairs(mappings) do
vim.api.nvim_buf_set_keymap(buffer, "n", key, func, {})
vim.api.nvim_buf_set_keymap(buffer, "n", key, func, { noremap = true })
end
end

Expand Down
6 changes: 6 additions & 0 deletions lua/dapui/windows/float.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local M = {}
local util = require("dapui.util")
local api = vim.api
local config = require("dapui.config")

Expand Down Expand Up @@ -92,6 +93,11 @@ function M.open_float(settings)
local position = settings.position or { line = line_no, col = col_no }
local opts = create_opts(settings.width, settings.height, position)
local content_buffer = settings.buffer or api.nvim_create_buf(false, true)
util.apply_mapping(
config.floating().mappings[config.FLOAT_MAPPINGS.CLOSE],
"<Cmd>q<CR>",
content_buffer
)
local content_window = api.nvim_open_win(content_buffer, false, opts)

local output_win_id = api.nvim_win_get_number(content_window)
Expand Down

0 comments on commit 90a4025

Please sign in to comment.