intellij-community
intellij-community copied to clipboard
Fix Incorrect File Selection in Merge Conflict Window Directory Tree by Preserving Expanded State
Problem:
When users collapse directories in the Merge Conflict window pop up and a refresh occurs (triggered by updateModelFromFiles(), for example when I open the file for merge and close it immediately), the previously selected file could be reselected incorrectly.
This issue stems from table.selectionModel.minSelectionIndex not accounting for the visibility (expanded/collapsed state) of files in the directory tree. Consequently, when the updateTree() function expands all directories during a refresh, the indices of files change, leading to a mismatch between the intended and actual selections.
Here is the visualization of the problem: https://imgur.com/gallery/sjJe84Y
Solution:
To address this issue, I implemented a strategy to preserve the user's context in the directory tree across updates. The solution involves the following steps:
- Save Expanded Paths
- After
updateTree()function is invoked, collapse the entire tree. - Restore expanded paths
This approach ensures that the directory tree's structure post-update remains identical to its state prior to the update. Consequently, the index saved in selIndex remains consistent.