@@ -3,6 +3,8 @@ local setup = require("dap-view.setup")
33
44local M = {}
55
6+ local api = vim .api
7+
68local winbar_info = {
79 breakpoints = {
810 desc = " Breakpoints [B]" ,
@@ -44,20 +46,21 @@ local winbar_info = {
4446 desc = " REPL [R]" ,
4547 keymap = " R" ,
4648 action = function ()
47- local winnr = state .winnr
48- -- Jump to dap-view's window to make the experience seamless
49- local cmd = " lua vim.api.nvim_set_current_win(" .. winnr .. " )"
50- local repl_buf , _ = require (" dap" ).repl .open (nil , cmd )
51- -- The REPL is a new buffer, so we need to set the winbar keymaps again
52- M .set_winbar_action_keymaps (repl_buf )
53- M .update_winbar (" repl" )
49+ if vim .tbl_contains (setup .config .winbar .sections , " repl" ) then
50+ -- Jump to dap-view's window to make the experience seamless
51+ local cmd = " lua vim.api.nvim_set_current_win(" .. state .winnr .. " )"
52+ local repl_buf , _ = require (" dap" ).repl .open (nil , cmd )
53+ -- The REPL is a new buffer, so we need to set the winbar keymaps again
54+ M .set_winbar_action_keymaps (repl_buf )
55+ M .update_winbar (" repl" )
56+ end
5457 end ,
5558 },
5659}
5760
5861--- @param bufnr ? integer
5962M .set_winbar_action_keymaps = function (bufnr )
60- if state .bufnr then
63+ if bufnr or state .bufnr then
6164 for _ , value in pairs (winbar_info ) do
6265 vim .keymap .set (" n" , value .keymap , function ()
6366 value .action ()
6871
6972--- @param selected_section SectionType
7073local set_winbar_opt = function (selected_section )
71- if state .winnr then
74+ if state .winnr and api . nvim_win_is_valid ( state . winnr ) then
7275 local winbar = setup .config .winbar .sections
7376 local winbar_title = {}
7477
@@ -94,21 +97,16 @@ local set_winbar_opt = function(selected_section)
9497 end
9598end
9699
97- --- @param selected_section ? SectionType
100+ --- @param selected_section SectionType
98101M .show_content = function (selected_section )
99102 winbar_info [selected_section ].action ()
100103end
101104
102- --- @param section_name SectionType
103- local _update_winbar = function (section_name )
104- state .current_section = section_name
105- set_winbar_opt (state .current_section )
106- end
107-
108105--- @param section_name SectionType
109106M .update_winbar = function (section_name )
110107 if setup .config .winbar .show then
111- _update_winbar (section_name )
108+ state .current_section = section_name
109+ set_winbar_opt (state .current_section )
112110 end
113111end
114112
0 commit comments