8888
8989function db :new_file ()
9090 vim .cmd (' enew' )
91- if self .user_laststatus_value then
92- vim .opt_local .laststatus = self .user_laststatus_value
93- self .user_laststatus_value = nil
94- end
91+ end
9592
96- if self . user_tabline_value then
97- vim . opt_local . showtabline = self . user_showtabline_value
98- self .user_showtabline_value = nil
99- end
93+ function db : save_user_options ()
94+ self . user_cursor_line = vim . opt . cursorline : get ()
95+ self .user_laststatus_value = vim . opt . laststatus : get ()
96+ self . user_tabline_value = vim . opt . showtabline : get ()
10097end
10198
102- -- cache the user options value restore after leave the dahsboard buffer
103- -- or use DashboardNewFile command
104- function db :cache_ui_options (opts )
99+ function db :set_ui_options (opts )
105100 if opts .hide .statusline then
106- --- @diagnostic disable-next-line : param-type-mismatch
107- self .user_laststatus_value = vim .opt .laststatus :get ()
108101 vim .opt .laststatus = 0
109102 end
110103 if opts .hide .tabline then
111- --- @diagnostic disable-next-line : param-type-mismatch
112- self .user_tabline_value = vim .opt .showtabline :get ()
113104 vim .opt .showtabline = 0
114105 end
115106end
116107
117- function db :restore_options ( )
108+ function db :restore_user_options ( opts )
118109 if self .user_cursor_line then
119110 vim .opt .cursorline = self .user_cursor_line
120- self .user_cursor_line = nil
121111 end
122112
123- if self .user_laststatus_value then
113+ if opts . hide . statusline and self .user_laststatus_value then
124114 vim .opt .laststatus = tonumber (self .user_laststatus_value )
125- self .user_laststatus_value = nil
126115 end
127116
128- if self .user_tabline_value then
117+ if opts . hide . tabline and self .user_tabline_value then
129118 vim .opt .showtabline = tonumber (self .user_tabline_value )
130- self .user_tabline_value = nil
131119 end
132120end
133121
@@ -210,7 +198,8 @@ function db:load_theme(opts)
210198 end
211199
212200 require (' dashboard.theme.' .. opts .theme )(config )
213- self :cache_ui_options (opts )
201+
202+ self :set_ui_options (opts )
214203
215204 api .nvim_create_autocmd (' VimResized' , {
216205 buffer = self .bufnr ,
@@ -222,13 +211,30 @@ function db:load_theme(opts)
222211
223212 api .nvim_create_autocmd (' BufEnter' , {
224213 callback = function (opt )
214+ if vim .bo .filetype == ' dashboard' then
215+ self :set_ui_options (opts )
216+ return
217+ end
218+
225219 local bufs = api .nvim_list_bufs ()
220+
226221 bufs = vim .tbl_filter (function (k )
227222 return vim .bo [k ].filetype == ' dashboard'
228223 end , bufs )
224+
225+ -- restore the user's UI settings is no dashboard buffers are visible
226+ local wins = api .nvim_tabpage_list_wins (0 )
227+ wins = vim .tbl_filter (function (k )
228+ return vim .tbl_contains (bufs , api .nvim_win_get_buf (k ))
229+ end , wins )
230+
231+ if # wins == 0 then
232+ self :restore_user_options (opts )
233+ end
234+
235+ -- clean up if there are no dashboard buffers at all
229236 if # bufs == 0 then
230237 self :cache_opts ()
231- self :restore_options ()
232238 clean_ctx ()
233239 pcall (api .nvim_del_autocmd , opt .id )
234240 end
@@ -259,7 +265,8 @@ function db:instance()
259265 self .winid = api .nvim_get_current_win ()
260266 api .nvim_win_set_buf (self .winid , self .bufnr )
261267
262- self .user_cursor_line = vim .opt .cursorline :get ()
268+ self :save_user_options ()
269+
263270 buf_local ()
264271 if self .opts then
265272 self :load_theme (self .opts )
0 commit comments