Skip to content

Commit 499b3fa

Browse files
committed
feat(windows): anchor main window to another window
1 parent 93d44eb commit 499b3fa

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

lua/dap-view/actions.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ M.open = function()
5757
local windows_config = setup.config.windows
5858

5959
local term_position = require("dap-view.util").inverted_directions[windows_config.terminal.position]
60+
local anchor_win = windows_config.anchor and windows_config.anchor()
61+
local is_anchor_win_valid = anchor_win and api.nvim_win_is_valid(anchor_win)
6062

6163
local winnr = api.nvim_open_win(bufnr, false, {
62-
split = is_term_win_valid and term_position or windows_config.position,
63-
win = is_term_win_valid and term_winnr or -1,
64+
split = (is_anchor_win_valid or is_term_win_valid) and term_position or windows_config.position,
65+
win = is_anchor_win_valid and anchor_win or is_term_win_valid and term_winnr or -1,
6466
height = windows_config.height < 1 and math.floor(vim.go.lines * windows_config.height)
6567
or windows_config.height,
6668
})

lua/dap-view/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local M = {}
1515
---@class dapview.WindowsConfig
1616
---@field height integer If > 1 number of lines, else percentage the windows should use
1717
---@field position 'right' | 'left' | 'above' | 'below'
18+
---@field anchor? fun(): integer? Function that returns a window number for the main nvim-dap-view window to follow
1819
---@field terminal dapview.TerminalConfig
1920

2021
---@class dapview.WinbarHeaders

lua/dap-view/setup/validate/help.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ function M.validate(config)
55
local validate = require("dap-view.setup.validate.util").validate
66

77
validate("help", {
8-
border = {
9-
config.border,
10-
function(v)
11-
return v == nil or type(v) == "string" or type(v) == "table"
12-
end,
13-
"string|string[]|nil",
14-
},
8+
border = { config.border, { "string", "table", "nil" } },
159
}, config)
1610
end
1711

lua/dap-view/setup/validate/windows.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function M.validate(config)
88
height = { config.height, "number" },
99
position = { config.position, "string" },
1010
terminal = { config.terminal, "table" },
11+
anchor = { config.anchor, { "function", "nil" } },
1112
}, config)
1213

1314
validate("windows.terminal", {

0 commit comments

Comments
 (0)