From d572a1ff795156e320faf68a35a87a8852902d67 Mon Sep 17 00:00:00 2001 From: eggu Date: Mon, 21 Aug 2023 22:04:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=E2=9C=A8=20Handle=20nil=20case=20f?= =?UTF-8?q?or=20selectedDir=20and=20selectedDirCell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added a check to handle the case when `selectedDir` and `selectedDirCell` are nil in `fileItemSelected` method. - If either `selectedDirCell` or `selectedDir` is nil, it returns early from the method. - This change ensures that the program won't crash when trying to access properties of nil values. --- tui/tui.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tui/tui.go b/tui/tui.go index 129a1401d..ac7715ace 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -215,15 +215,22 @@ func (ui *UI) rescanDir() { func (ui *UI) fileItemSelected(row, column int) { if ui.currentDir == nil { + return // Add this check to handle nil case + } + + selectedDirCell := ui.table.GetCell(row, column) + + // Check if the selectedDirCell is nil before using it + if selectedDirCell == nil || selectedDirCell.GetReference() == nil { return } - origDir := ui.currentDir - selectedDir := ui.table.GetCell(row, column).GetReference().(fs.Item) - if !selectedDir.IsDir() { + selectedDir := selectedDirCell.GetReference().(fs.Item) + if selectedDir == nil || !selectedDir.IsDir() { return } + origDir := ui.currentDir ui.currentDir = selectedDir ui.hideFilterInput() ui.markedRows = make(map[int]struct{})