summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreggu <shivamban30@gmail.com>2023-08-21 22:04:40 +0200
committerDaniel Milde <daniel@milde.cz>2024-02-12 22:38:24 +0100
commita25ff5d12425f57086fb013b40c4c0dad07ab145 (patch)
tree3624810f1671f5777219656b718fe9d9c5a1a0cd
parent3a0e5778cf9fb37ac121b823d95ac8baf692aee2 (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.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/tui/tui.go b/tui/tui.go
index 129a140..ac7715a 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{})