@@ -988,12 +988,27 @@ function FzfWin:set_tmp_buffer(no_wipe)
988988 return self .fzf_bufnr
989989end
990990
991- function FzfWin :set_style_minimal (winid )
992- if not tonumber (winid ) or
993- not api .nvim_win_is_valid (winid )
994- then
995- return
991+ function FzfWin :save_style_minimal (winid )
992+ if not tonumber (winid ) or not api .nvim_win_is_valid (winid ) then return end
993+ local ret = {}
994+ for _ , o in ipairs ({
995+ " number" ,
996+ " relativenumber" ,
997+ " cursorline" ,
998+ " cursorcolumn" ,
999+ " spell" ,
1000+ " list" ,
1001+ " signcolumn" ,
1002+ " foldcolumn" ,
1003+ " colorcolumn" ,
1004+ }) do
1005+ ret [o ] = vim .wo [winid ][o ]
9961006 end
1007+ return ret
1008+ end
1009+
1010+ function FzfWin :set_style_minimal (winid )
1011+ if not tonumber (winid ) or not api .nvim_win_is_valid (winid ) then return end
9971012 vim .wo [winid ].number = false
9981013 vim .wo [winid ].relativenumber = false
9991014 vim .wo [winid ].cursorline = false
@@ -1047,14 +1062,15 @@ function FzfWin:create()
10471062 self .cmdheight = vim .o .cmdheight
10481063
10491064 if self .winopts .split then
1065+ -- Store the current window styling options (number, cursor, etc)
1066+ self .src_winid_style = self :save_style_minimal (self .src_winid )
10501067 if type (self .winopts .split ) == " function" then
1051- local curwin = vim .api .nvim_get_current_win ()
10521068 self .winopts .split ()
1053- assert (curwin ~= vim .api .nvim_get_current_win (), " split function should return a new win" )
10541069 else
10551070 vim .cmd (tostring (self .winopts .split ))
10561071 end
10571072 local split_bufnr = vim .api .nvim_get_current_buf ()
1073+ assert (self .src_bufnr ~= split_bufnr , " split function should create a new buffer" )
10581074 self .fzf_winid = vim .api .nvim_get_current_win ()
10591075 if tonumber (self .fzf_bufnr ) and vim .api .nvim_buf_is_valid (self .fzf_bufnr ) then
10601076 -- Set to fzf bufnr set by `:unhide()`, wipe the new split buf
@@ -1126,7 +1142,16 @@ function FzfWin:close(fzf_bufnr, do_not_clear_cache)
11261142 -- run in a pcall due to potential errors while closing the window
11271143 -- Vim(lua):E5108: Error executing lua
11281144 -- experienced while accessing 'vim.b[]' from my statusline code
1129- pcall (vim .api .nvim_win_close , self .fzf_winid , true )
1145+ if self .src_winid == self .fzf_winid then
1146+ -- "split" reused the current win (e.g. "enew")
1147+ -- restore the original buffer and styling options
1148+ for k , v in pairs (self .src_winid_style or {}) do
1149+ vim .wo [self .fzf_winid ][k ] = v
1150+ end
1151+ utils .win_set_buf_noautocmd (self .fzf_winid , self .src_bufnr )
1152+ else
1153+ pcall (vim .api .nvim_win_close , self .fzf_winid , true )
1154+ end
11301155 end
11311156 if self .fzf_bufnr and vim .api .nvim_buf_is_valid (self .fzf_bufnr ) then
11321157 vim .api .nvim_buf_delete (self .fzf_bufnr , { force = true })
@@ -1137,9 +1162,10 @@ function FzfWin:close(fzf_bufnr, do_not_clear_cache)
11371162 -- window may not always return to the correct source win
11381163 -- depending on the user's split configuration (#397)
11391164 if self .winopts and self .winopts .split
1140- and self .src_winid and self .src_winid > 0
1165+ and tonumber (self .src_winid )
1166+ and vim .api .nvim_win_is_valid (self .src_winid )
11411167 and self .src_winid ~= vim .api .nvim_get_current_win ()
1142- and vim . api . nvim_win_is_valid ( self . src_winid ) then
1168+ then
11431169 vim .api .nvim_set_current_win (self .src_winid )
11441170 end
11451171 if self .winopts .split then
0 commit comments