@@ -87,38 +87,6 @@ function InlineDiff.new(args)
8787 return self
8888end
8989
90- --- Calculate diff hunks between two content arrays
91- --- @param args { context_lines ?: number , new_lines : string[] , old_lines : string[] }
92- --- @return CodeCompanion.Diff.Utils.DiffHunk[] hunks
93- function InlineDiff .calculate_hunks (args )
94- return diff_utils .calculate_hunks ({
95- added_lines = args .new_lines ,
96- context_lines = args .context_lines ,
97- removed_lines = args .old_lines ,
98- })
99- end
100-
101- --- Apply visual highlights to hunks in a buffer with sign column indicators
102- --- @param args { bufnr : number , hunks : CodeCompanion.Diff.Utils.DiffHunk[] , line_offset ?: number , ns_id : number , opts ?: table }
103- --- @return number[] extmark_ids
104- function InlineDiff .apply_hunk_highlights (args )
105- return diff_utils .apply_hunk_highlights ({
106- bufnr = args .bufnr ,
107- hunks = args .hunks ,
108- line_offset = args .line_offset ,
109- ns_id = args .ns_id ,
110- opts = args .opts ,
111- })
112- end
113-
114- --- Compares two content arrays for equality
115- --- @param content1 string[] First content array
116- --- @param content2 string[] Second content array
117- --- @return boolean equal True if contents are identical
118- function InlineDiff :is_equal (content1 , content2 )
119- return diff_utils .is_equal (content1 , content2 )
120- end
121-
12290--- Add keymap hint extmark above the first hunk
12391--- @param first_hunk CodeCompanion.Diff.Utils.DiffHunk First diff hunk
12492--- @param inline_config table Inline diff configuration
@@ -221,6 +189,60 @@ function InlineDiff:_clear_highlights()
221189 self .extmark_ids = {}
222190end
223191
192+ --- Clear winbar and winhighlight from the diff window
193+ --- @return nil
194+ function InlineDiff :_restore_winbar ()
195+ if self .winnr and api .nvim_win_is_valid (self .winnr ) then
196+ pcall (function ()
197+ vim .wo [self .winnr ].winbar = self .winbar .content
198+ vim .wo [self .winnr ].winhighlight = self .winbar .winhighlight
199+ end )
200+ end
201+ end
202+
203+ --- Close floating window if this diff is in a floating window
204+ --- @return nil
205+ function InlineDiff :_close_floating_window ()
206+ if self .is_floating and self .winnr and api .nvim_win_is_valid (self .winnr ) then
207+ log :debug (" [providers::diff::inline::close_floating_window] Closing floating window %d" , self .winnr )
208+ pcall (api .nvim_win_close , self .winnr , true )
209+ self .winnr = nil
210+ require (" codecompanion.utils.ui" ).close_background_window ()
211+ end
212+ end
213+
214+ --- Compares two content arrays for equality
215+ --- @param content1 string[] First content array
216+ --- @param content2 string[] Second content array
217+ --- @return boolean equal True if contents are identical
218+ function InlineDiff :is_equal (content1 , content2 )
219+ return diff_utils .is_equal (content1 , content2 )
220+ end
221+
222+ --- Apply visual highlights to hunks in a buffer with sign column indicators
223+ --- @param args { bufnr : number , hunks : CodeCompanion.Diff.Utils.DiffHunk[] , line_offset ?: number , ns_id : number , opts ?: table }
224+ --- @return number[] extmark_ids
225+ function InlineDiff .apply_hunk_highlights (args )
226+ return diff_utils .apply_hunk_highlights ({
227+ bufnr = args .bufnr ,
228+ hunks = args .hunks ,
229+ line_offset = args .line_offset ,
230+ ns_id = args .ns_id ,
231+ opts = args .opts ,
232+ })
233+ end
234+
235+ --- Calculate diff hunks between two content arrays
236+ --- @param args { context_lines ?: number , new_lines : string[] , old_lines : string[] }
237+ --- @return CodeCompanion.Diff.Utils.DiffHunk[] hunks
238+ function InlineDiff .calculate_hunks (args )
239+ return diff_utils .calculate_hunks ({
240+ added_lines = args .new_lines ,
241+ context_lines = args .context_lines ,
242+ removed_lines = args .old_lines ,
243+ })
244+ end
245+
224246--- Accepts the diff changes and clears highlights
225247--- @param opts ? { save : boolean }
226248--- @return nil
@@ -271,28 +293,6 @@ function InlineDiff:reject(opts)
271293 self :teardown ()
272294end
273295
274- --- Clear winbar and winhighlight from the diff window
275- --- @return nil
276- function InlineDiff :_restore_winbar ()
277- if self .winnr and api .nvim_win_is_valid (self .winnr ) then
278- pcall (function ()
279- vim .wo [self .winnr ].winbar = self .winbar .content
280- vim .wo [self .winnr ].winhighlight = self .winbar .winhighlight
281- end )
282- end
283- end
284-
285- --- Close floating window if this diff is in a floating window
286- --- @return nil
287- function InlineDiff :_close_floating_window ()
288- if self .is_floating and self .winnr and api .nvim_win_is_valid (self .winnr ) then
289- log :debug (" [providers::diff::inline::close_floating_window] Closing floating window %d" , self .winnr )
290- pcall (api .nvim_win_close , self .winnr , true )
291- self .winnr = nil
292- require (" codecompanion.utils.ui" ).close_background_window ()
293- end
294- end
295-
296296--- Cleans up the diff instance and fires detachment event
297297--- @return nil
298298function InlineDiff :teardown ()
0 commit comments