Skip to content

Commit

Permalink
Add a usevisible switchbuf option
Browse files Browse the repository at this point in the history
Closes #1328
  • Loading branch information
mfussenegger committed Sep 4, 2024
1 parent 281a2e4 commit f2e96ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/dap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@ The configuration values are set via `dap.defaults.fallback` (for global) or
See |'switchbuf'|. Defaults to the global `'switchbuf'`
setting.

nvim-dap provides an additional `usevisible` option
that can be used to prevent jumps within the active
window if a stopped event is within the visible region.
Best used in combination with other options. For
example: 'usevisible,usetab,uselast'

- `on_output`. A function with two parameters: `session` and `output_event`:
Overrides the default output handling with a custom handler.

Expand Down
11 changes: 11 additions & 0 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,17 @@ local function jump_to_location(bufnr, line, column, switchbuf, filetype)
return true
end

function switchbuf_fn.usevisible()
if api.nvim_win_get_buf(cur_win) == bufnr then
local first = vim.fn.line("w0", cur_win)
local last = vim.fn.line("w$", cur_win)
if first <= line and line <= last then
return true
end
end
return false
end

function switchbuf_fn.useopen()
if api.nvim_win_get_buf(cur_win) == bufnr then
set_cursor(cur_win, line, column)
Expand Down

0 comments on commit f2e96ba

Please sign in to comment.