Skip to content

Commit

Permalink
Merge pull request #529 from sahinfalcon/fix-delete-panic
Browse files Browse the repository at this point in the history
Fix panic when deleting last file in directory
  • Loading branch information
yorukot authored Dec 29, 2024
2 parents 1e86f64 + 12b5823 commit 6a644c1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/internal/handle_file_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ func (m *model) deleteSingleItem() {
message.processNewState = p
channel <- message
}
if panel.cursor == len(panel.element)-1 {
panel.cursor--
if len(panel.element) == 0 {
panel.cursor = 0
} else {
if panel.cursor >= len(panel.element) {
panel.cursor = len(panel.element) - 1
}
}
m.fileModel.filePanels[m.filePanelFocusIndex] = panel
}
Expand Down Expand Up @@ -258,8 +262,12 @@ func (m *model) completelyDeleteSingleItem() {
message.processNewState = p
channel <- message
}
if panel.cursor == len(panel.element)-1 {
panel.cursor--
if len(panel.element) == 0 {
panel.cursor = 0
} else {
if panel.cursor >= len(panel.element) {
panel.cursor = len(panel.element) - 1
}
}
m.fileModel.filePanels[m.filePanelFocusIndex] = panel
}
Expand Down

0 comments on commit 6a644c1

Please sign in to comment.