11local lazy = require (" diffview.lazy" )
22local oop = require (" diffview.oop" )
33
4+ local Diff1 = lazy .access (" diffview.scene.layouts.diff_1" , " Diff1" ) --- @type Diff1 | LazyModule
45local File = lazy .access (" diffview.vcs.file" , " File" ) --- @type vcs.File | LazyModule
6+ local GitAdapter = lazy .access (" diffview.vcs.adapters.git" , " GitAdapter" ) --- @type GitAdapter | LazyModule
57local RevType = lazy .access (" diffview.vcs.rev" , " RevType" ) --- @type RevType | LazyModule
68local config = lazy .require (" diffview.config" ) --- @module " diffview.config"
79local lib = lazy .require (" diffview.lib" ) --- @module " diffview.lib"
@@ -62,6 +64,12 @@ function Window:is_focused()
6264 return self :is_valid () and api .nvim_get_current_win () == self .id
6365end
6466
67+ function Window :is_file_open ()
68+ return self :is_valid ()
69+ and self .file :is_valid ()
70+ and api .nvim_win_get_buf (self .id ) == self .file .bufnr
71+ end
72+
6573--- @param callback fun ( file : vcs.File )
6674function Window :load_file (callback )
6775 assert (self .file )
@@ -87,11 +95,25 @@ function Window:open_file(callback)
8795 self :_save_winopts ()
8896 end
8997
90- self :apply_file_winopts ()
98+ local winopt_overrides
99+ local base_rev = utils .tbl_access (self , " parent.parent.revs.a" ) --[[ @as Rev? ]]
100+ local use_inline_diff = self .file .kind ~= " conflicting"
101+ and self .parent :instanceof (Diff1 .__get ())
102+ and self .file .adapter :instanceof (GitAdapter .__get ())
103+
104+ if use_inline_diff then
105+ winopt_overrides = { foldmethod = " manual" , diff = false }
106+ end
107+
108+ self :apply_file_winopts (winopt_overrides )
91109 self .file :attach_buffer (false , {
92110 keymaps = config .get_layout_keymaps (self .parent ),
93111 disable_diagnostics = self .file .kind == " conflicting"
94112 and config .get_config ().view .merge_tool .disable_diagnostics ,
113+ inline_diff = {
114+ enabled = use_inline_diff ,
115+ base = base_rev and base_rev :object_name (),
116+ }
95117 })
96118
97119 api .nvim_win_call (self .id , function ()
@@ -163,11 +185,16 @@ function Window:_restore_winopts()
163185 end
164186end
165187
166- function Window :apply_file_winopts ()
188+ --- @param overrides WindowOptions ?
189+ function Window :apply_file_winopts (overrides )
167190 assert (self .file )
168191 if self .file .winopts then
192+ if overrides then
193+ utils .set_local (self .id , vim .tbl_extend (" force" , self .file .winopts , overrides ))
194+ else
169195 utils .set_local (self .id , self .file .winopts )
170196 end
197+ end
171198end
172199
173200function Window :apply_null_winopts ()
0 commit comments