Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sublime opens new tab for same file #2158

Open
KES777 opened this issue Jan 11, 2018 · 13 comments
Open

Sublime opens new tab for same file #2158

KES777 opened this issue Jan 11, 2018 · 13 comments

Comments

@KES777
Copy link

KES777 commented Jan 11, 2018

Summary

kes@work ~/s $ echo $PWD
/home/kes/s
kes@work ~/s $ : > 1
kes@work ~/s $ subl 1
kes@work ~/s $ subl ~s/1

delete

The result is really bizarre if path has more symlinks

Expected behavior

delete

When file is opened from command line the current path should be used. And not new tab should be opened. Just line other editors do:

$ xed 1

delete

Actual behavior

File name is expanded to physical path.
The symlinks are called to shorten paths but Sublime Text make them back very very very very very very very ugly long

delete

Yes, to track same file and do not open same file twice or more times you can expand the path but please save it internally. When displaying show please the path the file is opened from.

Environment

  • Operating system and version:
    • Linux Mint 18.0
  • Sublime Text:
    delete

Please fix this behavior. It makes me hurt.

@keith-hall
Copy link
Collaborator

This is also possible to replicate on Windows without any symlinks by using the subst command:

subst f: c:\Windows
subl f:\win.ini
subl c:\windows\win.ini

The good news is that os.path.samefile correctly reports that the files are the same, so hopefully ST can use that (or something more efficient in C, maybe) to determine whether the file is already open in an ST window.

>>> files = [view.file_name() for view in sublime.active_window().views()[-2:]]; print(files); import os; os.path.samefile(*files)
['C:\\Windows\\win.ini', 'W:\\win.ini']
True

@titoBouzout
Copy link
Collaborator

@MarkGoldberg
Copy link

Please bump this up to a top priority,
as I've lost work several times and it's costing me confidence in ST3

I usually work with several different clones of the same file

Opening the file via SHIFT+P and then cloning opens one set of linked tabs
but opening the same file by clicking on a build error message sometimes opens a different set

Note: I found this issue via "files open to multiple tabs due to case in path" 37136
(sorry, I don't think I'm allowed to use URLs without logging in)

@evandrocoan
Copy link

evandrocoan commented Oct 31, 2018

@MarkGoldberg, until Sublime Text Core does not fixes it, and as keith-hall reported that os.path.samefile works, then, if I understand correctly the problem, you can write a plugin which monitors the files openings, then once you detect the same file has been already opened, you can close the new reference and focus on the old one.


Edit, I just missed that titoBouzout seems to already created one package fixing it:

  1. https://github.com/titoBouzout/PreventFakeClones

@KES777
Copy link
Author

KES777 commented Oct 31, 2018

To prevent corruption I may suggest to set ReadOnly flag on view which is clone

@staslisetsky
Copy link

I think I'm having the same issue in sublime 3 for windows (3176). I'm working with a project on a 'subst' drive. However when I disabled the subst, and reinstalled sublime, and removed the project, the issue still persisted. What I noticed is that the original file had uppercase drive letter in the path, and the duplicate had lowercase drive latter. I was able to fix the issue by changing the drive letter case in the workspace file and reopening all files. However, the fix only laster for maybe couple weeks. This is very strange. The duplicated tab always flickers when I save the original, and sometimes the chnages I make are not saved.

Been using sublime for a long time and this is such an unfortunate thing. Only started happening recently for me. Is there any news on this issue? I can provide more detailed information and help fix this.

@keith-hall
Copy link
Collaborator

regarding case sensitivity on Windows, this was fixed in build 3180

@staslisetsky
Copy link

@keith-hall Ah, yes, thank you. It's right there in the change logs. I forgot there are dev builds.

@Cerberus-tm
Copy link

https://github.com/titoBouzout/PreventFakeClones

Hey, nice work! Does your plug-in still work? I tried to install it but couldn't get it to work.

@titoBouzout
Copy link
Collaborator

@Cerberus-tm It does, Im using ST3 tho

@KES777
Copy link
Author

KES777 commented Apr 1, 2021

Nice plugin, but
would be nice if original issue will be fixed...

@titoBouzout
Copy link
Collaborator

I have to agree lol, I could understand why one may desire to open multiple instances of the same file without sharing a buffer, but allowing that by default its a recipe for disaster.... which is only noticed when you reach data loss, go figure

@KES777
Copy link
Author

KES777 commented May 27, 2021

@titoBouzout : By default sublime does not open new view for same file!
But if I open same file but path is differ (ala simlink) - new view is opened. This is inconsistent with default behavior!

Algorithm is next:

  1. expand file path to absolute (like pwd -P): ~/s/test -> /home/user/work/projects/vpn/test
  2. Open new view for this file. View should be named as ~/s/test (because I open this file)
  3. try to open ~/work/projects/vpn/test
  4. its file name expanded to absolute: -> /home/user/work/projects/vpn/test
  5. old view (opened at 1) becomes active (short name should not be changed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants