@@ -8,6 +8,48 @@ local nodes_module = require("codediff.ui.explorer.nodes")
88local tree_module = require (" codediff.ui.explorer.tree" )
99local keymaps_module = require (" codediff.ui.explorer.keymaps" )
1010local refresh_module = require (" codediff.ui.explorer.refresh" )
11+ local welcome = require (" codediff.ui.welcome" )
12+
13+ local function should_show_welcome (explorer )
14+ if not explorer or not explorer .git_root or explorer .dir1 or explorer .dir2 then
15+ return false
16+ end
17+
18+ local status = explorer .status_result or {}
19+ local total_files = # (status .unstaged or {}) + # (status .staged or {}) + # (status .conflicts or {})
20+ return total_files == 0
21+ end
22+
23+ local function show_welcome_page (explorer )
24+ local lifecycle = require (" codediff.ui.lifecycle" )
25+ local session = lifecycle .get_session (explorer .tabpage )
26+ if not session then
27+ return false
28+ end
29+
30+ local mod_win = session .modified_win
31+ if not mod_win or not vim .api .nvim_win_is_valid (mod_win ) then
32+ return false
33+ end
34+
35+ if session .layout == " inline" then
36+ local welcome_buf = welcome .create_buffer (vim .api .nvim_win_get_width (mod_win ), vim .api .nvim_win_get_height (mod_win ))
37+ require (" codediff.ui.view.inline_view" ).show_welcome (explorer .tabpage , welcome_buf )
38+ return true
39+ end
40+
41+ local orig_win = session .original_win
42+ local width = vim .api .nvim_win_get_width (mod_win )
43+ local height = vim .api .nvim_win_get_height (mod_win )
44+ if orig_win and vim .api .nvim_win_is_valid (orig_win ) then
45+ width = vim .api .nvim_win_get_width (orig_win ) + width + 1
46+ height = vim .api .nvim_win_get_height (orig_win )
47+ end
48+
49+ local welcome_buf = welcome .create_buffer (width , height )
50+ require (" codediff.ui.view.side_by_side" ).show_welcome (explorer .tabpage , welcome_buf )
51+ return true
52+ end
1153
1254function M .create (status_result , git_root , tabpage , width , base_revision , target_revision , opts )
1355 opts = opts or {}
@@ -132,12 +174,14 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
132174 on_file_select = nil , -- Will be set below
133175 current_file_path = nil , -- Track currently selected file
134176 current_file_group = nil , -- Track currently selected file's group (staged/unstaged)
177+ current_selection = nil , -- Full file selection used to replay current state
135178 is_hidden = false , -- Track visibility state
136179 visible_groups = vim .deepcopy (explorer_config .visible_groups or { staged = true , unstaged = true , conflicts = true }),
137180 }
138181
139182 -- File selection callback - manages its own lifecycle
140- local function on_file_select (file_data )
183+ local function on_file_select (file_data , opts )
184+ opts = opts or {}
141185 local git = require (" codediff.core.git" )
142186 local view = require (" codediff.ui.view" )
143187 local lifecycle = require (" codediff.ui.lifecycle" )
@@ -164,7 +208,7 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
164208
165209 -- Check if already displaying same file
166210 local session = lifecycle .get_session (tabpage )
167- if session and session .original_path == original_path and session .modified_path == modified_path then
211+ if not opts . force and session and session .original_path == original_path and session .modified_path == modified_path then
168212 return
169213 end
170214
@@ -190,7 +234,9 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
190234 vim .schedule (function ()
191235 local sess = lifecycle .get_session (tabpage )
192236 if sess and sess .layout == " inline" then
193- require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , abs_path )
237+ require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , abs_path , {
238+ side = " modified" ,
239+ })
194240 else
195241 require (" codediff.ui.view.side_by_side" ).show_untracked_file (tabpage , abs_path )
196242 end
@@ -206,19 +252,31 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
206252
207253 if base_revision and target_revision and target_revision ~= " WORKING" then
208254 if is_inline then
209- require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , { revision = target_revision , git_root = git_root , rel_path = file_path })
255+ require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , {
256+ revision = target_revision ,
257+ git_root = git_root ,
258+ rel_path = file_path ,
259+ side = " modified" ,
260+ })
210261 else
211262 require (" codediff.ui.view.side_by_side" ).show_added_virtual_file (tabpage , git_root , file_path , target_revision )
212263 end
213264 elseif group == " staged" then
214265 if is_inline then
215- require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , { revision = " :0" , git_root = git_root , rel_path = file_path })
266+ require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , {
267+ revision = " :0" ,
268+ git_root = git_root ,
269+ rel_path = file_path ,
270+ side = " modified" ,
271+ })
216272 else
217273 require (" codediff.ui.view.side_by_side" ).show_added_virtual_file (tabpage , git_root , file_path , " :0" )
218274 end
219275 else
220276 if is_inline then
221- require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , abs_path )
277+ require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , abs_path , {
278+ side = " modified" ,
279+ })
222280 else
223281 require (" codediff.ui.view.side_by_side" ).show_untracked_file (tabpage , abs_path )
224282 end
@@ -235,14 +293,24 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
235293
236294 if base_revision and target_revision and target_revision ~= " WORKING" then
237295 if is_inline then
238- require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , { revision = base_revision , git_root = git_root , rel_path = file_path })
296+ require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , {
297+ revision = base_revision ,
298+ git_root = git_root ,
299+ rel_path = file_path ,
300+ side = " original" ,
301+ })
239302 else
240303 require (" codediff.ui.view.side_by_side" ).show_deleted_virtual_file (tabpage , git_root , file_path , base_revision )
241304 end
242305 else
243306 if is_inline then
244307 local revision = (group == " staged" ) and " HEAD" or " :0"
245- require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , { revision = revision , git_root = git_root , rel_path = file_path })
308+ require (" codediff.ui.view.inline_view" ).show_single_file (tabpage , file_path , {
309+ revision = revision ,
310+ git_root = git_root ,
311+ rel_path = file_path ,
312+ side = " original" ,
313+ })
246314 else
247315 require (" codediff.ui.view.side_by_side" ).show_deleted_file (tabpage , git_root , file_path , abs_path , group )
248316 end
@@ -257,7 +325,7 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
257325 if session then
258326 local is_same_file = (session .modified_path == abs_path or (session .git_root and session .original_path == file_path ))
259327
260- if is_same_file then
328+ if is_same_file and not opts . force then
261329 -- Check if it's the same diff comparison
262330 local is_staged_diff = group == " staged"
263331 local current_is_staged = session .modified_revision == " :0"
@@ -391,13 +459,21 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
391459 end
392460
393461 -- Wrap on_file_select to track current file and group
394- explorer .on_file_select = function (file_data )
462+ explorer .on_file_select = function (file_data , opts )
395463 explorer .current_file_path = file_data .path
396464 explorer .current_file_group = file_data .group
465+ explorer .current_selection = vim .deepcopy (file_data )
397466 selected_path = file_data .path
398467 selected_group = file_data .group
399468 tree :render ()
400- on_file_select (file_data )
469+ on_file_select (file_data , opts )
470+ end
471+
472+ -- Clear selection highlight (used when showing welcome page)
473+ explorer .clear_selection = function ()
474+ selected_path = nil
475+ selected_group = nil
476+ tree :render ()
401477 end
402478
403479 -- Setup keymaps (delegated to keymaps module)
@@ -485,6 +561,31 @@ function M.create(status_result, git_root, tabpage, width, base_revision, target
485561 return explorer
486562end
487563
564+ function M .rerender_current (explorer )
565+ if not explorer then
566+ return false
567+ end
568+
569+ if explorer .current_selection then
570+ explorer .on_file_select (vim .deepcopy (explorer .current_selection ), { force = true })
571+ return true
572+ end
573+
574+ local lifecycle = require (" codediff.ui.lifecycle" )
575+ local session = lifecycle .get_session (explorer .tabpage )
576+ if not session then
577+ return false
578+ end
579+
580+ if should_show_welcome (explorer ) and show_welcome_page (explorer ) then
581+ return true
582+ end
583+
584+ return false
585+ end
586+
587+ M .show_welcome_page = show_welcome_page
588+
488589-- Setup auto-refresh on file save and focus
489590
490591return M
0 commit comments