@@ -179,32 +179,34 @@ local function open_in_new_window(filename, mode, win_ids)
179179 if not target_winid then
180180 return
181181 end
182- local do_split = mode == " split" or mode == " vsplit"
183- local split_side = (view .View .side == " right" ) and " aboveleft" or " belowright"
182+
183+ local create_new_window = # api .nvim_list_wins () == 1
184+ local new_window_side = (view .View .side == " right" ) and " aboveleft" or " belowright"
184185
185186 -- Target is invalid or window does not exist in current tabpage: create new window
186187 if not vim .tbl_contains (win_ids , target_winid ) then
187- vim .cmd (split_side .. " vsplit" )
188+ vim .cmd (new_window_side .. " vsplit" )
188189 target_winid = api .nvim_get_current_win ()
189190 lib .target_winid = target_winid
190191
191192 -- No need to split, as we created a new window.
192- do_split = false
193+ create_new_window = false
193194 elseif not vim .o .hidden then
194195 -- If `hidden` is not enabled, check if buffer in target window is
195196 -- modified, and create new split if it is.
196197 local target_bufid = api .nvim_win_get_buf (target_winid )
197198 if api .nvim_buf_get_option (target_bufid , " modified" ) then
198- do_split = true
199+ mode = " vsplit "
199200 end
200201 end
201202
202203 local fname = vim .fn .fnameescape (filename )
203204
204205 local cmd
205- if do_split or # api .nvim_list_wins () == 1 then
206- local split_cmd = (mode ~= " split" ) and " vsplit" or " split"
207- cmd = string.format (" %s %s %s" , split_side , split_cmd , fname )
206+ if create_new_window then
207+ cmd = string.format (" %s vsplit %s" , new_window_side , fname )
208+ elseif mode :match " split$" then
209+ cmd = string.format (" %s %s" , mode , fname )
208210 else
209211 cmd = string.format (" edit %s" , fname )
210212 end
0 commit comments