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

Several problems with "save_on_focus_lost" settings #980

Open
FichteFoll opened this issue Sep 1, 2015 · 7 comments
Open

Several problems with "save_on_focus_lost" settings #980

FichteFoll opened this issue Sep 1, 2015 · 7 comments

Comments

@FichteFoll
Copy link
Collaborator

The save_on_focus_lost setting behaves too strict in many situations, causing all of the following:

  1. Trying to edit a read-only file and then switching the window causes an infinite loop of "Access denied" and "Overwrite read-only file?" dialogs. ("save_on_focus_lost" and Read-Only files jskinner/DefaultPackages#88)
  2. "Save As..." is essentially useless if you made changes before running that command, becase the "Save As" dialog causes ST to lose focus and the file is saved to its original name in the background. ("Save As..." Menu Option with "save_on_focus_lost" Setting #110)
  3. When closing a view, the opening dialog that asks if you want to save or discard changes (or cancel) also causes the file to lose focus and it is saved regarless of the option chosen. ("Save As..." Menu Option with "save_on_focus_lost" Setting #110)
  4. Find and Replace with a buffered context, where all candidate replacements are opened in "dirty" views, the changes are always saved when each one gains and then loses. ("Save As..." Menu Option with "save_on_focus_lost" Setting #110)
  5. Invoking any kind of command via Command Palette or any command that uses a Quick Panel or Input Panel triggers the save. If you have trim_trailing_white_space_on_save enabled and wanted to invoke the command at the end of the line with some whitespace before, the whitespace would get trimmed completely. Currently, plugins need to disable the settings before opening any kind of panel in order to work around this.

Please keep posting similar problems with save_on_focus_lost in this issue.


Added from comments:

  1. "Show unsaved Changes" is pretty much unusable.
FichteFoll added a commit to FichteFoll/InsertDate that referenced this issue Sep 1, 2015
Sublime Text would automatically save the file otherwise and potentially
perform other on_save actions such as trimming trailing whitespace.

Addresses #26.

See sublimehq/sublime_text#980.
@vovkkk
Copy link

vovkkk commented Sep 1, 2015

Please keep posting similar issues with save_on_focus_lost in this issue.

Not really similar, but a systemic problem.

Show unsaved changes becomes sort of unusable, because diff is too literal; while user (me at least) probably want to see diff between original state (when file was open) and current one (disregarding any saves in-between); no it has nothing to do with version control systems (file could be already changed from vcs pov, when it was open in ST, or not being tracked by vcs at all).
And sure, despite this inconvenience, I prefer having save on focus lost enabled, since it is only way for kind of autosave.

@l-gothberg
Copy link

l-gothberg commented Feb 9, 2018

Cursor is moved to EOF on when "save_on_focus_lost" : "true"

This is annoying in the extreme when switching back and forth between a external terminal window.

@ratijas
Copy link

ratijas commented Jun 24, 2020

I second this. Got myself into "sudo lock": constantly appearing dialogues asking for sudo password to use /bin/cp. Even worse, the system dialogue doesn't explain which files will be copied, but that's out of scope.

@ratijas
Copy link

ratijas commented Aug 30, 2020

Related: #3603

@princemaple
Copy link

Closed my #4065 "Do not treat opening command palette / quick panel as focus lost" in favor of this one.

@gemisigo
Copy link

gemisigo commented Dec 7, 2021

Command Palette and Revert do not mix well either when save_on_focus_lost is turned on. As soon as the Command Palette is summoned, any pending changes get saved to the file, and subsequently invoking Revert from the Command Palette is flogging a dead horse.

The Preference.sublime-settings file has a short definition attached to the setting save_on_focus_lost:

Set to true to automatically save files when switching to a different file or application

None of those apply when you invoke the Command Palette. No switching to other files or applications happens.

@martinstark
Copy link

martinstark commented Jan 10, 2023

Using Sublime with LSP: Rename and save_on_focus_lost does not work as expected (for me). I'm looking at migrating from JetBrains products where you never have to manually save, and things just work.

Performing a Refactor/Rename that touches multiple file paths will open each of the edited files in Sublime, with focus on the last file. Switching focus to a different app will then only save the last file, not every file that was edited by the LSP: Rename action.

To save the files, you have to manually go back and tab through each file in order focus/unfocus to save them, nullifying the purpose of "auto save".

The workflow:

  1. perform a LSP: Rename that touches several paths in a large monorepo
  2. switch focus to a terminal to build the project
  3. the build fails, since only the last touched path was saved by Sublime

I would expect all edited files to be saved on focus lost, I guess this could be achieved by making the LSP: Rename (and other) actions give focus to each file that it touches, in order to allow all of them to save automatically, or introducing a "save_all_on_focus_lost" option.

The way JetBrains handles a refactor action is to auto save each file, and allowing a single Undo action to revert the entire Rename action, undoing changes to each path touched.

I would consider this a bug, but maybe it should be a separate feature request issue? Personally, after getting used to working in a world where manually saving is not a thing anymore I don't think I'd want to migrate to Sublime and re-learn to save again.

(sidenote: I'm working on a blog post for migrating from WebStorm -> Sublime, but haven't been able to get Sublime all the way to the "just works" mark yet)

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

7 participants