File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,13 +19,29 @@ return function(view)
1919 view :set_file (file , false , true )
2020 end
2121
22+ -- Restore panel cursor position.
23+ if view .panel_cursor and view .panel :is_open () then
24+ local winid = view .panel :get_winid ()
25+ if winid and api .nvim_win_is_valid (winid ) then
26+ pcall (api .nvim_win_set_cursor , winid , view .panel_cursor )
27+ end
28+ end
29+
2230 if view .ready then
2331 view :update_files ()
2432 end
2533 end ,
2634 tab_leave = function ()
2735 local file = view .panel .cur_file
2836
37+ -- Save panel cursor position.
38+ if view .panel :is_open () then
39+ local winid = view .panel :get_winid ()
40+ if winid and api .nvim_win_is_valid (winid ) then
41+ view .panel_cursor = api .nvim_win_get_cursor (winid )
42+ end
43+ end
44+
2945 if file then
3046 file .layout :detach_files ()
3147 end
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ local lib = lazy.require("diffview.lib") ---@module "diffview.lib"
88local utils = lazy .require (" diffview.utils" ) --- @module " diffview.utils"
99local vcs_utils = lazy .require (" diffview.vcs.utils" ) --- @module " diffview.vcs.utils"
1010
11+ local api = vim .api
1112local await = async .await
1213
1314--- @param view FileHistoryView
@@ -18,10 +19,26 @@ return function(view)
1819 if file then
1920 view :set_file (file )
2021 end
22+
23+ -- Restore panel cursor position.
24+ if view .panel_cursor and view .panel :is_open () then
25+ local winid = view .panel :get_winid ()
26+ if winid and api .nvim_win_is_valid (winid ) then
27+ pcall (api .nvim_win_set_cursor , winid , view .panel_cursor )
28+ end
29+ end
2130 end ,
2231 tab_leave = function ()
2332 local file = view .panel .cur_item [2 ]
2433
34+ -- Save panel cursor position.
35+ if view .panel :is_open () then
36+ local winid = view .panel :get_winid ()
37+ if winid and api .nvim_win_is_valid (winid ) then
38+ view .panel_cursor = api .nvim_win_get_cursor (winid )
39+ end
40+ end
41+
2542 if file then
2643 file .layout :detach_files ()
2744 end
You can’t perform that action at this time.
0 commit comments