Skip to content

Commit 73cb92d

Browse files
author
Sindre T. Strøm
committed
fix: Nil value indexing while inferring file (fixes #397)
1 parent 285ce7a commit 73cb92d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lua/diffview/scene/views/diff/diff_view.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,17 +526,15 @@ end
526526
---Returns nil if no file is open in the view, or there is no entry under the
527527
---cursor in the file panel.
528528
---@param allow_dir? boolean Allow directory nodes from the file tree.
529-
---@return FileEntry|DirData|nil
529+
---@return (FileEntry|DirData)?
530530
function DiffView:infer_cur_file(allow_dir)
531531
if self.panel:is_focused() then
532532
---@type any
533533
local item = self.panel:get_item_at_cursor()
534+
if not item then return end
535+
if not allow_dir and type(item.collapsed) == "boolean" then return end
534536

535-
if FileEntry.__get():ancestorof(item)
536-
or (allow_dir and type(item.collapsed) == "boolean")
537-
then
538-
return item
539-
end
537+
return item
540538
else
541539
return self.panel.cur_file
542540
end

0 commit comments

Comments
 (0)