Sublime Forum

File is savable when file is unmodified

#1

If I open a file, then add a character “a”, and then remove character “a” that I just wrote, the file will become “dirty” or “savable”. However, the file contents were not changed. Other editors (Atom, VSCode) will look if the file content has changed before allowing the user to save. Is this a bug or expected behavior in ST3?

0 Likes

#2

I beleive that this is expected behaviour, as Sublime seems to track the dirty state of the file based on the list of edits that have been applied and not on their cumulative visual effect on the file contents.

So for example pressing ABackspace makes the file visually appear the same (and thus apparently not dirty) but there are still two unsaved edits, so it’s still considered dirty.

On the other hand, pressing ACtrl+Z (i.e. Undo) removes the original edit, which takes the file back to an unmodified state and correctly marks the file as no longer dirty.

Aside of that, Sublime also always saves the file when you press save, even if the buffer is currently considered unmodified.

0 Likes

#3

Thank you for your response! Is it possible to show the visual effect ONLY if the file CONTENTS is modified? It doesn’t make sense to save a file when the contents has not actually been changed.

0 Likes

#4

Technically speaking, that’s what it’s doing, just at a more granular level than you want. As far as I’m aware the only setting related to this is the one that enables or disables marking the tab of the file as being dirty if it has any changes made that haven’t been saved, but nothing that makes it track visual/structural changes alone.

I think the only way to clear the dirty state is to either undo all of the changes since the last save or save the file, so there’s no simple plugin way to make it do that either. I could be wrong, though.

0 Likes

#5

If your project is under version control like git, then GitSavvy displays in the status bar if the file is modified (or committed), even in the presence of an edit history.

0 Likes