Skip to content

Commit

Permalink
editor: save dirty editors with auto-save on
Browse files Browse the repository at this point in the history
The following commit triggers a `saveAll` (for all dirty content), when
the `auto-save` is turned on.

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Jul 14, 2020
1 parent a1ea230 commit bec48d1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/editor/src/browser/editor-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { inject, injectable } from 'inversify';
import { inject, injectable, postConstruct } from 'inversify';
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common';
import URI from '@theia/core/lib/common/uri';
import { CommonCommands, PreferenceService, QuickPickItem, QuickPickService, LabelProvider, QuickPickValue } from '@theia/core/lib/browser';
import { CommonCommands, PreferenceService, QuickPickItem, QuickPickService, LabelProvider, QuickPickValue, Saveable } from '@theia/core/lib/browser';
import { Languages, Language } from '@theia/languages/lib/browser';
import { EditorManager } from './editor-manager';
import { EncodingMode } from './editor';
Expand Down Expand Up @@ -163,6 +163,17 @@ export class EditorCommandContribution implements CommandContribution {
@inject(ResourceProvider)
protected readonly resourceProvider: ResourceProvider;

@postConstruct()
protected async init(): Promise<void> {
this.editorPreferences.onPreferenceChanged(e => {
if (e.preferenceName === 'editor.autoSave' && e.newValue === 'on') {
this.editorManager.all
.filter(editor => Saveable.isDirty(editor))
.forEach(editor => Saveable.save(editor));
}
});
}

registerCommands(registry: CommandRegistry): void {
registry.registerCommand(EditorCommands.SHOW_REFERENCES);
registry.registerCommand(EditorCommands.CONFIG_INDENTATION);
Expand Down

0 comments on commit bec48d1

Please sign in to comment.