1
1
local lazy = require (" diffview.lazy" )
2
2
local oop = require (" diffview.oop" )
3
3
4
+ local Diff1 = lazy .access (" diffview.scene.layouts.diff_1" , " Diff1" ) --- @type Diff1 | LazyModule
4
5
local File = lazy .access (" diffview.vcs.file" , " File" ) --- @type vcs.File | LazyModule
6
+ local GitAdapter = lazy .access (" diffview.vcs.adapters.git" , " GitAdapter" ) --- @type GitAdapter | LazyModule
5
7
local RevType = lazy .access (" diffview.vcs.rev" , " RevType" ) --- @type RevType | LazyModule
6
8
local config = lazy .require (" diffview.config" ) --- @module " diffview.config"
7
9
local lib = lazy .require (" diffview.lib" ) --- @module " diffview.lib"
@@ -62,6 +64,12 @@ function Window:is_focused()
62
64
return self :is_valid () and api .nvim_get_current_win () == self .id
63
65
end
64
66
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
+
65
73
--- @param callback fun ( file : vcs.File )
66
74
function Window :load_file (callback )
67
75
assert (self .file )
@@ -87,11 +95,25 @@ function Window:open_file(callback)
87
95
self :_save_winopts ()
88
96
end
89
97
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 )
91
109
self .file :attach_buffer (false , {
92
110
keymaps = config .get_layout_keymaps (self .parent ),
93
111
disable_diagnostics = self .file .kind == " conflicting"
94
112
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
+ }
95
117
})
96
118
97
119
api .nvim_win_call (self .id , function ()
@@ -163,11 +185,16 @@ function Window:_restore_winopts()
163
185
end
164
186
end
165
187
166
- function Window :apply_file_winopts ()
188
+ --- @param overrides WindowOptions ?
189
+ function Window :apply_file_winopts (overrides )
167
190
assert (self .file )
168
191
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
169
195
utils .set_local (self .id , self .file .winopts )
170
196
end
197
+ end
171
198
end
172
199
173
200
function Window :apply_null_winopts ()
0 commit comments