Skip to content

Commit bec48d1

Browse files
editor: save dirty editors with auto-save on
The following commit triggers a `saveAll` (for all dirty content), when the `auto-save` is turned on. Signed-off-by: vince-fugnitto <[email protected]>
1 parent a1ea230 commit bec48d1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/editor/src/browser/editor-command.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
********************************************************************************/
1616

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

166+
@postConstruct()
167+
protected async init(): Promise<void> {
168+
this.editorPreferences.onPreferenceChanged(e => {
169+
if (e.preferenceName === 'editor.autoSave' && e.newValue === 'on') {
170+
this.editorManager.all
171+
.filter(editor => Saveable.isDirty(editor))
172+
.forEach(editor => Saveable.save(editor));
173+
}
174+
});
175+
}
176+
166177
registerCommands(registry: CommandRegistry): void {
167178
registry.registerCommand(EditorCommands.SHOW_REFERENCES);
168179
registry.registerCommand(EditorCommands.CONFIG_INDENTATION);

0 commit comments

Comments
 (0)