Skip to content

Commit cd8781a

Browse files
committed
feat: DapViewJump command
1 parent f9071c8 commit cd8781a

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,18 @@ to the watch list. The threads view has 2 mappings:
169169
When you finish your session, you can use `:DapViewClose` to close the
170170
`nvim-dap-view` window.
171171

172-
In total, there are 4 commands:
172+
In total, there are 5 commands:
173173

174174
- `DapViewOpen`
175175
- `DapViewClose`
176176
- `DapViewToggle`
177177
- `DapViewWatch`
178+
- `DapViewJump [view]`
179+
180+
You can `:DapViewJump [view]` to jump directly to a view, from any window. For instance, to jump to the REPL, you can use `:DapViewJump repl` to jump to REPL.
178181

179182
Additionally, you can use `DapViewClose!` and `DapViewToggle!` to also hide the
180-
terminal window, if you prefer a tidy view.
183+
terminal window, if you'd rather have a tidy view.
181184

182185
If you prefer using lua functions, I got you covered! The following provide the
183186
same functionality as above:
@@ -189,6 +192,7 @@ require("dap-view").close(true) -- Same as `DapViewClose!`
189192
require("dap-view").toggle()
190193
require("dap-view").toggle(true) -- Same as `DapViewToggle!`
191194
require("dap-view").add_expr()
195+
require("dap-view").jump("[view]") -- Can be used to jump to a specific view, from any window
192196
```
193197

194198
`nvim-dap-view` doesn't define any keybindings (outside its own buffer, of

lua/dap-view.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ M.add_expr = function()
2929
actions.add_expr()
3030
end
3131

32+
---@param view SectionType
33+
M.jump_to_view = function(view)
34+
actions.jump_to_view(view)
35+
end
36+
3237
return M

lua/dap-view/actions.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,18 @@ M.add_expr = function()
8484
end
8585
end
8686

87+
---@param view SectionType
88+
M.jump_to_view = function(view)
89+
if not vim.tbl_contains(setup.config.winbar.sections, view) then
90+
vim.notify("Can't jump to unconfigured view: " .. view)
91+
return
92+
end
93+
if state.bufnr and state.winnr and api.nvim_win_is_valid(state.winnr) then
94+
api.nvim_set_current_win(state.winnr)
95+
winbar.show_content(view)
96+
else
97+
vim.notify("Can't jump to view: couldn't find the window")
98+
end
99+
end
100+
87101
return M

plugin/dap-view.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ command("DapViewToggle", function(opts)
88
require("dap-view").toggle(opts.bang)
99
end, { bang = true })
1010
command("DapViewWatch", require("dap-view").add_expr, {})
11+
command("DapViewJump", function(opts)
12+
require("dap-view").jump_to_view(opts.fargs[1])
13+
end, { nargs = 1 })

0 commit comments

Comments
 (0)