Skip to content

fix(gui): prevent crash on right-click in Project Explorer with no selection#510

Open
bhavyabhardwaj001 wants to merge 2 commits into
FOSSEE:masterfrom
bhavyabhardwaj001:fix/project-explorer-rightclick
Open

fix(gui): prevent crash on right-click in Project Explorer with no selection#510
bhavyabhardwaj001 wants to merge 2 commits into
FOSSEE:masterfrom
bhavyabhardwaj001:fix/project-explorer-rightclick

Conversation

@bhavyabhardwaj001
Copy link
Copy Markdown

Related Issues

Closes #509


Purpose

The Project Explorer context menu crashes when a user right-clicks without selecting any item. This happens because the current implementation relies on selectedIndexes() and assumes that a selection is always present.


Approach

  • Replaced selectedIndexes() with indexAt(position) to determine the item under the cursor
  • Added index.isValid() check to safely handle right-clicks on empty areas
  • Set the clicked index as the current selection to maintain expected menu behavior
  • Used a temporary index (temp_index) to safely traverse parent hierarchy and compute level

Changes Made

  • Updated openMenu() implementation in ProjectExplorer.py
  • Removed unsafe access to indexes[0]
  • Refactored logic to depend on actual user interaction instead of prior selection state
  • Ensured level is always initialized before use

Impact

  • Prevents application crash on right-click with no selection
  • Improves robustness and consistency of context menu behavior
  • Maintains existing functionality for valid selections

Verification

  • Right-click on empty space → no crash, no unintended behavior
  • Right-click on project/file → context menu opens correctly
  • Right-click on nested items → correct level detection and menu behavior

…on in Project Explorer

Replaced selectedIndexes()-based logic with indexAt(position) to correctly handle right-click events.

- Prevents crash when no item is selected
- Ensures only valid indexes are used
- Aligns behavior with expected context menu interaction
- Ensures level is always defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Application crashes on right-click in empty Project Explorer space

1 participant