Skip to content

Commit

Permalink
🔧✨ Handle nil case for selectedDir and selectedDirCell
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
ShivamB25 authored and dundee committed Feb 12, 2024
1 parent 3a0e577 commit a25ff5d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down

0 comments on commit a25ff5d

Please sign in to comment.