Skip to content

Commit

Permalink
Fixing Sentry #OPENSHOT-YG: IndexError: pop index out of range when m…
Browse files Browse the repository at this point in the history
…oving unselected items up/down on Add to Timeline dialog.
  • Loading branch information
jonoomph committed Jul 8, 2024
1 parent 8c4c769 commit 10a24e5
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/windows/add_to_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ def btnMoveUpClicked(self, checked):
if self.treeFiles.selected:
selected_index = self.treeFiles.selected.row()

# Ignore if empty files
# Ignore if empty files or no selection
if not files or selected_index is None:
return

# New index
new_index = max(selected_index - 1, 0)
log.info(new_index)
# Check if selected_index is within valid range
if 0 <= selected_index < len(files):
# New index
new_index = max(selected_index - 1, 0)

# Remove item and move it
files.insert(new_index, files.pop(selected_index))
# Remove item and move it
files.insert(new_index, files.pop(selected_index))
else:
log.warning(f"Invalid selected_index: {selected_index}, list length: {len(files)}")
return

# Refresh tree
self.treeFiles.refresh_view()
Expand All @@ -90,16 +94,20 @@ def btnMoveDownClicked(self, checked):
if self.treeFiles.selected:
selected_index = self.treeFiles.selected.row()

# Ignore if empty files
# Ignore if empty files or no selection
if not files or selected_index is None:
return

# New index
new_index = min(selected_index + 1, len(files) - 1)
log.info(new_index)
# Check if selected_index is within valid range
if 0 <= selected_index < len(files):
# New index
new_index = min(selected_index + 1, len(files) - 1)

# Remove item and move it
files.insert(new_index, files.pop(selected_index))
# Remove item and move it
files.insert(new_index, files.pop(selected_index))
else:
log.warning(f"Invalid selected_index: {selected_index}, list length: {len(files)}")
return

# Refresh tree
self.treeFiles.refresh_view()
Expand Down

0 comments on commit 10a24e5

Please sign in to comment.