From d37aff1b9960049be493d2d0ec215b8b9c2ea503 Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 20 Mar 2025 23:35:18 -0300 Subject: [PATCH] Add tabusevisible switchbuf option --- doc/dap.txt | 11 ++++++----- lua/dap/session.lua | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/dap.txt b/doc/dap.txt index 813695f2..be2cc1f0 100644 --- a/doc/dap.txt +++ b/doc/dap.txt @@ -592,11 +592,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' + nvim-dap provides an additional `usevisible` + (`tabusevisible`) option that can be used to prevent + jumps within the active window (tab) 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. diff --git a/lua/dap/session.lua b/lua/dap/session.lua index 687090f3..6e1a1cad 100644 --- a/lua/dap/session.lua +++ b/lua/dap/session.lua @@ -427,6 +427,7 @@ local function jump_to_location(bufnr, line, column, switchbuf, filetype) end local cur_win = api.nvim_get_current_win() + local cur_tab = api.nvim_win_get_tabpage(cur_win) local switchbuf_fn = {} function switchbuf_fn.uselast() @@ -456,6 +457,19 @@ local function jump_to_location(bufnr, line, column, switchbuf, filetype) return false end + function switchbuf_fn.tabusevisible() + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(cur_tab)) do + if api.nvim_win_get_buf(win) == bufnr then + local first = vim.fn.line("w0", win) + local last = vim.fn.line("w$", win) + if first <= line and line <= last then + return true + end + 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)