sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

[Linux] Open file should use sublime instance from current virtual desktop

Open Mq89 opened this issue 6 years ago • 21 comments

Summary

Opening a file via command line subl file.md or via file browser opens the file in the last used sublime instance which might be located on another desktop in a virtual desktop environment of Linux such as Openbox.

Expected behavior

Opening a file via

  1. command line (subl file.md)
  2. file browser
  3. (CTRL-Left Mouse in a PDF created with LaTeXTools and Synctex)

should open the respective file in

  • a sublime instance located on the current virtual desktop
  • (potentially create a new sublime instance if none is existent on the current virtual desktop. From commandline you can already use subl -n file.md for that)

Actual behavior

The file appears in the recently used sublime instance that might be on a different virtual desktop. This behavior is cumbersome, because you have to find the particular instance, or click the instance on the current virtual desktop and reopen the file.

Steps to reproduce

  1. Open two sublime instances on virtual desktops A and B
  2. Focus sublime on desktop A
  3. Go to desktop B without focusing sublime
  4. Open file for sublime via e.g. your file browser
  5. The file will be opened on desktop A

Environment

  • Operating system and version:
    • Linux: Lubuntu 16.10 with LXDE and Openbox (but should be applicable to all environments using virtual desktops)
  • Sublime Text:
    • Build 3143 (most likely not limited to this build)
    • 64 bit

Mq89 avatar Apr 18 '18 07:04 Mq89

Related issues are:

  • for Windows: #1773
  • for OS X: #333

Mq89 avatar Apr 18 '18 07:04 Mq89

Also #2267

FichteFoll avatar Apr 18 '18 12:04 FichteFoll

Also this happens on Ubuntu 18.04.

I switched to Visual Code due to this bug.

orinciog avatar Jun 20 '18 12:06 orinciog

Is there any update on this bug?

dileepkr avatar Sep 24 '18 17:09 dileepkr

No, but I also don't know how fixable this is. I'm not aware of a generally standardized API between various window managers on Linux and since you have the choice between many, you'd either end up having to hardcode workarounds for the most common window managers (probably at least those from entire desktop environments like Gnome and KDE).

The other option would be to write a short (shell) script that interfaces with the WM's API to determine whether there is an ST window in the current virtual desktop and, depending on whether that is the case, add or remove the -n flag from the subl call. However, you cannot choose which window to open a file in from, so that would be a feature that needs to be added to the CLI. Or you write a custom command in a plugin that handles this lookup for now and that you call from the command line.

FichteFoll avatar Sep 24 '18 17:09 FichteFoll

No, but I also don't know how fixable this is. I'm not aware of a generally standardized API [...]

Yeah, I don't know how other applications do it, but I know many of them do. The one that comes to mind immediately is Chrome, but with a huge dev team an Google money, I'd believe it if someone told me they just wrote a fix for every Linux window manager they could find.

CoryOwens avatar Sep 24 '18 19:09 CoryOwens

Any updates? This issue is quite bothersome. I am finding myself increasingly using gedit for "quick edits" to avoid having to look through N workspaces for the latest Sublime window.

seib2 avatar May 14 '19 13:05 seib2

This issue is annoying and bothering the user on Linux. Please consider it seriously and fix it. I'm thinking about VS code because of this bug.

vryy avatar Feb 13 '20 08:02 vryy

I want to echo the same concern, this is really annoying because it causes a sudden mental context switch that comes with workspace switch. physically this is equivalent to picking up an object an suddenly finding yourself in a different room so you forget what is it I wanted to do in first place. I am a paid customer but often find myself using geany or something else to avoid this. you guys need to fix this.

DesiCoder99 avatar Jun 17 '20 20:06 DesiCoder99

I want to echo the same concern, this is really annoying because it causes a sudden mental context switch that comes with workspace switch. physically this is equivalent to picking up an object an suddenly finding yourself in a different room so you forget what is it I wanted to do in first place. I am a paid customer but often find myself using geany or something else to avoid this. you guys need to fix this.

I agreed with you. I bought Sublime and now I regret about this. This is a simple thing to fix and if the developer do not want to fix that, they are going to lose customer.

vryy avatar Jun 17 '20 21:06 vryy

I've written https://github.com/tsantzi/launch_sublime to help me with this. Only tested under Linux/Cinnamon, but should be easy to adapt. Needs wmctrl installed.

tsantzi avatar Oct 16 '20 10:10 tsantzi

I did not have this problem on my Kubuntu laptop until I had to reformat & reinstall. So why did it occur? What did I have that made it work without this problem before? The only thing I can think of is I was using a different task switcher. I changed it back to 'Thumbnails', like my original install and now when I open Sublime, it opens in the background on the current workspace. Switching back to 'Breeze' task switcher does not cause the problem to recur. So I'm not clear what I've done to fix it. But I had the problem you are reporting, and I was able to get it to disappear by changing my task switcher.

Not sure if this helps at all.

Marupio avatar Jan 27 '22 17:01 Marupio

@tsantzi 's script works for me (Ubuntu 20.04), but I agree this should be fixed in subl itself. If it requires some WM-specific code, then that's probably just the cost of doing business on a particular OS. Although I sympathize with how annoying this would be to maintain for Ubuntu in particular, where Canonical seems unable to break the habit of throwing out major components of their windowing stack every couple versions.

tsbertalan avatar May 04 '22 16:05 tsbertalan

Ah, no, I spoke too soon. It seems that, even with ps aux | grep subl returning no results, subl -n (or /opt/sublime_text/sublime_text --new-window) insists on opening on a different desktop than the one I'm testing from. There's really no excuse for this; there's no previous instance to be confused with.

I can fix it temporarily by deleting or renaming ~/.config/sublime-text/Local/Session.sublime_session. It's not a great solution, but if you don't care about "session"s, you can just add rm $HOME/.config/sublime-text/Local/Session.sublime_session to the script from @tsantzi . At this point, I just use sublime as a basic editor, and VSC for anything serious, so I'm fine with that.

A more fine-grained approach might be to parse that file (it's JSON) and strip out some sort of workspace information, but how to do this minimally without losing things like my menu-hide preference (why isn't this in ~/.config/sublime-text-Packages/User/Preferences.sublime-settings instead, BTW?) would take me more than 0 minutes of effort, so I'm going with the brute-force method now.

tsbertalan avatar May 04 '22 16:05 tsbertalan

Hi @tsbertalan, yes, this weird behaviour of subl -n jumping to another workspace started happening on my system too, a few months ago. Note that it only happens sometimes/rarely (at least on Arch+Cinnamon, which is what I use).

Frankly I have given up hope on this ever working properly, I have spent way too many hours trying to fix this. It is sad because I am/was a huge fan of Sublime for many years (it being my main driver/IDE), but this issue renders it unusable with my workflow, which involves spreading out multiple projects across my workspaces.

FWIW, the script still works properly when opening sublime "projects" (although you have to open them via the sublime-workspace file, as opening the sublime-project file will occasionally cause sublime to crash - another long-standing issue on Linux).

If you want to look into tweaking the JSON file before launch, you can try https://github.com/trentm/json to do so, it works great. However, after having a quick glance at Session.sublime_session, I could not figure out any workspace information that could be tweaked.

Best of luck!

tsantzi avatar May 05 '22 09:05 tsantzi

Oh, sure, if I were to go the config-editing route, I'd probably use the python stdlib. But I'd still be deleting things that subl thought were important to save, which seems pretty wrong. Anyway, as I said, my workaround is good enough if you see subl as more of a one-off editor than a full IDE, which is how I use it.

tsbertalan avatar May 24 '22 22:05 tsbertalan

You can add "remember_workspace": false to your settings file remember_workspace makes Sublime Text remember what workspace each window was in last. When set to false the OS left to determine which workspace a window is opened in. This doesn't work with Wayland. It worked for me.

adip1343 avatar Jul 16 '22 06:07 adip1343

@adip1343 Thanks, that seems to work on Windows, at least. I'll keep the workaround on Linux, and I guess check back in a few months (or maybe whenever I update my Ubuntu from 20.04) to see if remember_workspace is honored there.

tsbertalan avatar Sep 06 '22 02:09 tsbertalan

"remember_workspace": false in Ubuntu 22.04 worked for me. Thanks, @adip1343

odellcraig avatar Nov 17 '23 19:11 odellcraig

I can confirm that "remember_workspace": false also worked for me in Ubuntu 22.04

@odellcraig, thanks a lot!!!!

xepost avatar Nov 30 '23 11:11 xepost

What a stupid behavior. This is annoying for every user working with multiple workspaces. Funnily i ditched GNOME-text-editor due to that and thought something more advanced like sublime would honor logical behaviour (no developer wants any file to open on a different workspace within a completely unrelated context). But wow, even here. Can not believe it.

sudo apt purge sublime-text

cls-nebadje avatar Feb 24 '24 10:02 cls-nebadje