Skip to content

Commit 3bad682

Browse files
jakubbortlikharrisoncramer
authored andcommitted
Fix: Jumping to renamed files (#484)
* fix: prevent "cursor position outside buffer" error * fix: swap file_name and old_file_name in reviewer data `old_file_name` is not set to the empty string for un-renamed files anymore, because then we can remove the empty-line check in `comment_helpers.go` which was used to replace the empty string with the current file name anyway. * fix: add old_file_name to discussion root node data * fix: also consider old_file_name when jumping to the reviewer This fixes jumping to renamed files, however, may not work for comments that were created on renamed files with the previous version of `gitlab.nvim` as that version assigned the `file_name` and `old_file_name` incorrectly. * refactor: don't shadow variable * fix: check file_name or old_file_name based on which SHA comment belongs to
1 parent 9f898aa commit 3bad682

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lua/gitlab/reviewer/init.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ M.jump = function(file_name, old_file_name, line_number, new_buffer)
123123

124124
local files = view.panel:ordered_file_list()
125125
local file = List.new(files):find(function(f)
126-
return new_buffer and f.path == file_name or f.oldpath == old_file_name
126+
local oldpath = f.oldpath ~= nil and f.oldpath or f.path
127+
return new_buffer and f.path == file_name or oldpath == old_file_name
127128
end)
128129
if file == nil then
129130
u.notify(
@@ -195,10 +196,8 @@ M.get_reviewer_data = function(current_win)
195196
local opposite_bufnr = new_sha_focused and layout.a.file.bufnr or layout.b.file.bufnr
196197

197198
return {
198-
-- TODO: swap 'a' and 'b' to fix lua/gitlab/actions/comment.lua:158, and hopefully also
199-
-- lua/gitlab/indicators/diagnostics.lua:129.
200-
file_name = layout.a.file.path,
201-
old_file_name = M.is_file_renamed() and layout.b.file.path or "",
199+
old_file_name = M.is_file_renamed() and layout.a.file.path or "",
200+
file_name = layout.b.file.path,
202201
old_line_from_buf = old_line,
203202
new_line_from_buf = new_line,
204203
modification_type = modification_type,

0 commit comments

Comments
 (0)