Skip to content

Commit c68d444

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 c68d444

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 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, ApplicationShell } 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';
@@ -140,6 +140,9 @@ export class EditorCommandContribution implements CommandContribution {
140140

141141
public static readonly AUTOSAVE_PREFERENCE: string = 'editor.autoSave';
142142

143+
@inject(ApplicationShell)
144+
protected readonly shell: ApplicationShell;
145+
143146
@inject(PreferenceService)
144147
protected readonly preferencesService: PreferenceService;
145148

@@ -163,6 +166,17 @@ export class EditorCommandContribution implements CommandContribution {
163166
@inject(ResourceProvider)
164167
protected readonly resourceProvider: ResourceProvider;
165168

169+
@postConstruct()
170+
protected init(): void {
171+
this.editorPreferences.onPreferenceChanged(e => {
172+
if (e.preferenceName === 'editor.autoSave') {
173+
if (this.isAutoSaveOn()) {
174+
this.shell.saveAll();
175+
}
176+
}
177+
});
178+
}
179+
166180
registerCommands(registry: CommandRegistry): void {
167181
registry.registerCommand(EditorCommands.SHOW_REFERENCES);
168182
registry.registerCommand(EditorCommands.CONFIG_INDENTATION);

0 commit comments

Comments
 (0)