Repository: spyder-ide/spyder

Issue:
Outline duplicates files when Editor is split
I'm having a weird issue with the Outline in which when the Editor is split - the filenames duplicate. And it's just the filenames, i.e. you can't expand/compress them, or remove them for that matter. This really curbs workflow especially when working with a lot files in a split Editor window. So much so that I have stopped using the Outline and am forced to scroll through the files ...

Here's an example when I have multiple files opened in a monolithic Editor pane:

![image](https://user-images.githubusercontent.com/15214418/105714471-ae202f80-5f1c-11eb-93de-4474d60bac63.png)

Now when I do `Split horizontally` (same happens for a vertical split), the Outline gets messed up like so (notice that only every second entry can be expanded):

![image](https://user-images.githubusercontent.com/15214418/105714605-dc057400-5f1c-11eb-9627-504841c0aa58.png)

The messed up Outline persists even when I close the split. It's corrected if I reset Spyder.


## Versions

* Spyder version: 4.2.1 None
* Python version: 3.6.12 64-bit
* Qt version: 5.12.9
* PyQt5 version: 5.12.3
* Operating System: Linux 5.4.85-1-MANJARO


### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  4.0.0 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.0.2 (OK)
IPython >=7.6.0                 :  7.16.1 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
keyring >=17.0.0                :  21.8.0 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.8.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.8.0 (OK)
pygments >=2.0                  :  2.7.3 (OK)
pylint >=1.0                    :  2.6.0 (OK)
pyls >=0.36.2;<1.0.0            :  0.36.2 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.3.0             :  0.3.0 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.2 (OK)
qtconsole >=5.0.1               :  5.0.1 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
rtree >=0.8.3                   :  0.9.7 (OK)
setuptools >=39.0.0             :  49.6.0.post20210108 (OK)
sphinx >=0.6.6                  :  3.4.3 (OK)
spyder_kernels >=1.10.1;<1.11.0 :  1.10.1 (OK)
textdistance >=4.2.0            :  4.2.0 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3               :  1.0.2 (OK)
xdg >=0.26                      :  0.26 (OK)
zmq >=17                        :  21.0.0 (OK)

# Optional:
cython >=0.21                   :  0.29.21 (OK)
matplotlib >=2.0.0              :  3.3.3 (OK)
numpy >=1.7                     :  1.19.5 (OK)
pandas >=1.1.1                  :  1.1.5 (OK)
scipy >=0.17.0                  :  1.5.3 (OK)
sympy >=0.7.3                   :  1.4 (OK)
```



Discussion:
Hi @gerazov

Thanks for reporting, we will work in fixing this issue.

@andfoy can you take a look at this one?
This also persists in Spyder 5.0.0

This is no longer a problem in our latest version (5.1.1). @gerazov, could you confirm if you're still seeing this problem?
In deed - it's fixed! I'm closing - thanks guys :pray: 
Hello there. I still have the same issue.

If I remove the ".spyder-py3" folder in my user folder (on Windows) and then open up an existing Spyder-project, at first it is fine. But after a couple of Spyder restarts the duplicates in outline return. This is a very vague description... I know. Is there something I can provide to help?

* Spyder version: 5.1.1 None
* Python version: 3.7.10 64-bit
* Qt version: 5.12.5
* PyQt5 version: 5.12.3
* Operating System: Windows 10
The outline received several improvements in 5.1.2. So please update to 5.1.3 and try again. 
Thanks for the quick advise, but it unfortunately did not help.
I did:
- update to to 5.1.3
- remove  ".spyder-py3" folder
- start Spyder and configure some settings
- load my project
- show outline pane
- split the view
- Restart Spyder
- -> Now all files have duplicates in outline

I thought my project might be broken? Next thing I tried:
- Close project
- Restart Spyder
- Create new empty project
- (has single editor view)
- Load some files
- The very moment I click "split horizontally", duplicates appear in the outline view

Wow, this might be important!
- I had "sort files alphabetically" checked in the outline
- As I uncheck that checkbox, the duplicates disappear!
- **And I can reproduce it: If I hit "split view" while "sort files alphabetically" is activated, the duplicates appear** 👍 

Versions:
* Spyder version: 5.1.3 None
* Python version: 3.7.10 64-bit
* Qt version: 5.12.5
* PyQt5 version: 5.12.3
* Operating System: Windows 10
> And I can reproduce it: If I hit "split view" while "sort files alphabetically" is activated, the duplicates appear +1

@jnettels, thanks for letting us how to reproduce this problem! I followed your instructions and I also see duplicate file names in the Outline.

We'll try to fix this in our next version (5.2.0). to be released next month. 
@ccordoba12 I was unable to reproduce this with Spyder 5.3.0 using the Windows standalone version:

![imagen](https://user-images.githubusercontent.com/16781833/163454066-ef0b4634-05fb-4a75-a18a-b0f29f9134d8.png)

@jnettels could you check if using the Windows installer available at our release page (https://github.com/spyder-ide/spyder/releases/latest) helps in your case? Thank you and let us know!
@dalthviz, what's missing from @jnettels description is that you also need to activate the option called `Show all files` in the Outline.

With that, I'm still getting the duplicates mentioned in this issue:

![imagen](https://user-images.githubusercontent.com/365293/163466079-8e927fb4-c22f-4a0d-8164-0350253fdfa4.png)

Oh I see, now I'm getting the error :+1:

![imagen](https://user-images.githubusercontent.com/16781833/163466940-113a3da1-f05b-40fc-a82f-99a991632b60.png)


Resolving patch:
diff --git a/spyder/plugins/outlineexplorer/widgets.py b/spyder/plugins/outlineexplorer/widgets.py
--- a/spyder/plugins/outlineexplorer/widgets.py
+++ b/spyder/plugins/outlineexplorer/widgets.py
@@ -717,9 +717,16 @@ def __sort_toplevel_items(self):
 
         current_ordered_items = [self.topLevelItem(index) for index in
                                  range(self.topLevelItemCount())]
+
+        # Convert list to a dictionary in order to remove duplicated entries
+        # when having multiple editors (splitted or in new windows).
+        # See spyder-ide/spyder#14646
+        current_ordered_items_dict = {
+            item.path.lower(): item for item in current_ordered_items}
+
         if self.sort_files_alphabetically:
             new_ordered_items = sorted(
-                current_ordered_items,
+                current_ordered_items_dict.values(),
                 key=lambda item: osp.basename(item.path.lower()))
         else:
             new_ordered_items = [


Test patch: