@@ -157,8 +157,16 @@ function M.goto_file_tab()
157157 end
158158end
159159
160- --- Jump to the next merge conflict marker.
161- function M .next_conflict ()
160+ --- @class diffview.ConflictCount
161+ --- @field total integer
162+ --- @field current integer
163+ --- @field cur_conflict ? ConflictRegion
164+ --- @field conflicts ConflictRegion[]
165+
166+ --- @param num integer
167+ --- @param use_delta ? boolean
168+ --- @return diffview.ConflictCount ?
169+ function M .jumpto_conflict (num , use_delta )
162170 local view = lib .get_current_view ()
163171
164172 if view and view :instanceof (StandardView .__get ()) then
@@ -167,13 +175,29 @@ function M.next_conflict()
167175 local curfile = main .file
168176
169177 if main :is_valid () and curfile :is_valid () then
170- local conflicts , _ , cur_idx = vcs_utils .parse_conflicts (
178+ local next_idx
179+ local conflicts , cur , cur_idx = vcs_utils .parse_conflicts (
171180 api .nvim_buf_get_lines (curfile .bufnr , 0 , - 1 , false ),
172181 main .id
173182 )
174183
175184 if # conflicts > 0 then
176- local next_idx = math.min (cur_idx , # conflicts ) % # conflicts + 1
185+ if not use_delta then
186+ next_idx = utils .clamp (num , 1 , # conflicts )
187+ else
188+ local delta = num
189+
190+ if not cur and delta < 0 and cur_idx <= # conflicts then
191+ delta = delta + 1
192+ end
193+
194+ if (delta < 0 and cur_idx < 1 ) or (delta > 0 and cur_idx > # conflicts ) then
195+ cur_idx = utils .clamp (cur_idx , 1 , # conflicts )
196+ end
197+
198+ next_idx = (cur_idx + delta - 1 ) % # conflicts + 1
199+ end
200+
177201 local next_conflict = conflicts [next_idx ]
178202 local curwin = api .nvim_get_current_win ()
179203
@@ -183,40 +207,28 @@ function M.next_conflict()
183207 end )
184208
185209 api .nvim_echo ({{ (" Conflict [%d/%d]" ):format (next_idx , # conflicts ) }}, false , {})
210+
211+ return {
212+ total = # conflicts ,
213+ current = next_idx ,
214+ cur_conflict = next_conflict ,
215+ conflicts = conflicts ,
216+ }
186217 end
187218 end
188219 end
189220end
190221
222+ --- Jump to the next merge conflict marker.
223+ --- @return diffview.ConflictCount ?
224+ function M .next_conflict ()
225+ return M .jumpto_conflict (1 , true )
226+ end
227+
191228--- Jump to the previous merge conflict marker.
229+ --- @return diffview.ConflictCount ?
192230function M .prev_conflict ()
193- local view = lib .get_current_view ()
194-
195- if view and view :instanceof (StandardView .__get ()) then
196- --- @cast view StandardView
197- local main = view .cur_layout :get_main_win ()
198- local curfile = main .file
199-
200- if main :is_valid () and curfile :is_valid () then
201- local conflicts , _ , cur_idx = vcs_utils .parse_conflicts (
202- api .nvim_buf_get_lines (curfile .bufnr , 0 , - 1 , false ),
203- main .id
204- )
205-
206- if # conflicts > 0 then
207- local prev_idx = (math.max (cur_idx , 1 ) - 2 ) % # conflicts + 1
208- local prev_conflict = conflicts [prev_idx ]
209- local curwin = api .nvim_get_current_win ()
210-
211- api .nvim_win_call (main .id , function ()
212- api .nvim_win_set_cursor (main .id , { prev_conflict .first , 0 })
213- if curwin ~= main .id then view .cur_layout :sync_scroll () end
214- end )
215-
216- api .nvim_echo ({{ (" Conflict [%d/%d]" ):format (prev_idx , # conflicts ) }}, false , {})
217- end
218- end
219- end
231+ return M .jumpto_conflict (- 1 , true )
220232end
221233
222234--- Execute `cmd` for each target window in the current view. If no targets
0 commit comments