Skip to content

Commit 2e00e2d

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Added a workaround for Theia's auto-save issue.
Ref: eclipse-theia/theia#8722 Signed-off-by: Akos Kitta <[email protected]>
1 parent ca1b288 commit 2e00e2d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import { ListItemRenderer } from './widgets/component-list/list-item-renderer';
6565
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
6666
import { MonacoThemingService } from '@theia/monaco/lib/browser/monaco-theming-service';
6767
import { ArduinoDaemonPath, ArduinoDaemon } from '../common/protocol/arduino-daemon';
68-
import { EditorManager as TheiaEditorManager } from '@theia/editor/lib/browser';
68+
import { EditorManager as TheiaEditorManager, EditorCommandContribution as TheiaEditorCommandContribution } from '@theia/editor/lib/browser';
6969
import { EditorManager } from './theia/editor/editor-manager';
7070
import { FrontendConnectionStatusService, ApplicationConnectionStatusContribution } from './theia/core/connection-status-service';
7171
import {
@@ -124,6 +124,7 @@ import { NotificationServicePath, NotificationServiceServer } from '../common/pr
124124
import { About } from './contributions/about';
125125
import { IconThemeService } from '@theia/core/lib/browser/icon-theme-service';
126126
import { TabBarRenderer } from './theia/core/tab-bars';
127+
import { EditorCommandContribution } from './theia/editor/editor-command';
127128

128129
const ElementQueries = require('css-element-queries/src/ElementQueries');
129130

@@ -341,4 +342,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
341342
const iconThemeService = context.container.get<IconThemeService>(IconThemeService);
342343
return new TabBarRenderer(contextMenuRenderer, decoratorService, iconThemeService);
343344
});
345+
346+
// Workaround for https://github.com/eclipse-theia/theia/issues/8722
347+
// Do not trigger a save on IDE startup if `"editor.autoSave": "on"` was set as a preference.
348+
bind(EditorCommandContribution).toSelf().inSingletonScope();
349+
rebind(TheiaEditorCommandContribution).toService(EditorCommandContribution);
344350
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { injectable, postConstruct } from 'inversify';
2+
import { EditorCommandContribution as TheiaEditorCommandContribution } from '@theia/editor/lib/browser/editor-command';
3+
4+
@injectable()
5+
export class EditorCommandContribution extends TheiaEditorCommandContribution {
6+
7+
@postConstruct()
8+
protected init(): void {
9+
// Workaround for https://github.com/eclipse-theia/theia/issues/8722.
10+
this.editorPreferences.onPreferenceChanged(({ preferenceName, newValue, oldValue }) => {
11+
if (preferenceName === 'editor.autoSave') {
12+
const autoSaveWasOnBeforeChange = !oldValue || oldValue === 'on';
13+
const autoSaveIsOnAfterChange = !newValue || newValue === 'on';
14+
if (!autoSaveWasOnBeforeChange && autoSaveIsOnAfterChange) {
15+
this.shell.saveAll();
16+
}
17+
}
18+
});
19+
}
20+
21+
}

0 commit comments

Comments
 (0)