Skip to content

Commit

Permalink
fix: handle cursor position after deleting last file in directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sahinfalcon committed Dec 29, 2024
1 parent c7fce5c commit 32a9b19
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 32a9b19

Please sign in to comment.