diff options
author | eggu <shivamban30@gmail.com> | 2023-08-21 22:04:40 +0200 |
---|---|---|
committer | Daniel Milde <daniel@milde.cz> | 2024-02-12 22:38:24 +0100 |
commit | a25ff5d12425f57086fb013b40c4c0dad07ab145 (patch) | |
tree | 3624810f1671f5777219656b718fe9d9c5a1a0cd | |
parent | 3a0e5778cf9fb37ac121b823d95ac8baf692aee2 (diff) |
🔧✨ Handle nil case for selectedDir and selectedDirCell
- 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.
-rw-r--r-- | tui/tui.go | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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{}) |