File tree 1 file changed +23
-1
lines changed
arduino-ide-extension/src/browser/contributions
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { injectable } from '@theia/core/shared/inversify' ;
2
+ import { toArray } from '@theia/core/shared/@phosphor/algorithm' ;
2
3
import * as remote from '@theia/core/electron-shared/@electron/remote' ;
3
4
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor' ;
4
5
import type { MaybePromise } from '@theia/core/lib/common/types' ;
@@ -35,7 +36,28 @@ export class Close extends SketchContribution {
35
36
36
37
override registerCommands ( registry : CommandRegistry ) : void {
37
38
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
+ } ,
39
61
} ) ;
40
62
}
41
63
You can’t perform that action at this time.
0 commit comments