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

Theia runs save on app startup if "editor.autoSave": "on" is configured in the settings.json #8722

Closed
kittaakos opened this issue Nov 6, 2020 · 3 comments · Fixed by #13683
Labels
bug bugs found in the application
Milestone

Comments

@kittaakos
Copy link
Contributor

When I have the following settings.json in my workspace and the app starts, a save event will be fired from the editor commands:

settings.json:

{
  "editor.autoSave": "on"
}

this.editorPreferences.onPreferenceChanged(e => {
if (e.preferenceName === 'editor.autoSave' && e.newValue === 'on') {
this.shell.saveAll();
}
});

Theia incorrectly assumes there was a preference change, but there wasn't. Auto-save is enabled by default, so I would expect the exact same behavior when I have an empty settings.json or one with "editor.autoSave": "on".

Steps to Reproduce:

Additional Information

  • Operating System:
  • Theia Version:
@kittaakos kittaakos added the bug bugs found in the application label Nov 6, 2020
@kittaakos
Copy link
Contributor Author

This PR causes the undesired side effect.

@kittaakos
Copy link
Contributor Author

Nice, the default auto-save preference is off:

But editor command ignores this and assumes auto-save if on when not set:

return autoSave === 'on' || autoSave === undefined;

@kittaakos
Copy link
Contributor Author

kittaakos commented Nov 6, 2020

Here is a workaround for the time being:

your-module.ts:

bind(EditorCommandContribution).toSelf().inSingletonScope();
rebind(TheiaEditorCommandContribution).toService(EditorCommandContribution);

your-editor-commands.ts:

import { injectable, postConstruct } from 'inversify';
import { EditorCommandContribution as TheiaEditorCommandContribution } from '@theia/editor/lib/browser/editor-command';

@injectable()
export class EditorCommandContribution extends TheiaEditorCommandContribution {

    @postConstruct()
    protected init(): void {
        // Workaround for https://github.com/eclipse-theia/theia/issues/8722.
        this.editorPreferences.onPreferenceChanged(({ preferenceName, newValue, oldValue }) => {
            if (preferenceName === 'editor.autoSave') {
                const autoSaveWasOnBeforeChange = !oldValue || oldValue === 'on';
                const autoSaveIsOnAfterChange = !newValue || newValue === 'on';
                if (!autoSaveWasOnBeforeChange && autoSaveIsOnAfterChange) {
                    this.shell.saveAll();
                }
            }
        });
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application
Projects
None yet
2 participants