Skip to content

Commit 0608fe4

Browse files
author
Akos Kitta
committed
Restored logic to close current closable widget
and then the window. Signed-off-by: Akos Kitta <[email protected]>
1 parent 5e668ff commit 0608fe4

File tree

1 file changed

+23
-1
lines changed
  • arduino-ide-extension/src/browser/contributions

1 file changed

+23
-1
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/close.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { injectable } from '@theia/core/shared/inversify';
2+
import { toArray } from '@theia/core/shared/@phosphor/algorithm';
23
import * as remote from '@theia/core/electron-shared/@electron/remote';
34
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
45
import type { MaybePromise } from '@theia/core/lib/common/types';
@@ -35,7 +36,28 @@ export class Close extends SketchContribution {
3536

3637
override registerCommands(registry: CommandRegistry): void {
3738
registry.registerCommand(Close.Commands.CLOSE, {
38-
execute: () => remote.getCurrentWindow().close(),
39+
execute: () => {
40+
// Close current editor if closeable.
41+
const { currentEditor } = this.editorManager;
42+
if (currentEditor && currentEditor.title.closable) {
43+
currentEditor.close();
44+
return;
45+
}
46+
47+
if (this.shell) {
48+
// Close current widget from the main area if possible.
49+
const { currentWidget } = this.shell;
50+
if (currentWidget) {
51+
const currentWidgetInMain = toArray(
52+
this.shell.mainPanel.widgets()
53+
).find((widget) => widget === currentWidget);
54+
if (currentWidgetInMain && currentWidgetInMain.title.closable) {
55+
return currentWidgetInMain.close();
56+
}
57+
}
58+
}
59+
return remote.getCurrentWindow().close();
60+
},
3961
});
4062
}
4163

0 commit comments

Comments
 (0)