@@ -2,18 +2,28 @@ import { EditorEvent, IEditorTab } from 'mo/model/workbench/editor';
2
2
import { Controller } from 'mo/react/controller' ;
3
3
import { editorService } from 'mo/services' ;
4
4
import { singleton } from 'tsyringe' ;
5
-
6
5
export interface IEditorController {
6
+ groupSplitPos ?: string [ ] ;
7
7
onCloseAll ?: ( group : number ) => void ;
8
8
onCloseTab ?: ( tabKey : string , group : number ) => void ;
9
9
onMoveTab ?: < T = any > ( updateTabs : IEditorTab < T > [ ] , group : number ) => void ;
10
10
onSelectTab ?: ( tabKey : string , group : number ) => void ;
11
11
onSplitEditorRight ?: ( ) => void ;
12
12
onUpdateEditorIns ?: ( editorInstance : any , groupId : number ) => void ;
13
+ onPaneSizeChange ?: ( newSize : number ) => void ;
14
+ onTabContextMenu ?: ( e : React . MouseEvent , tab : IEditorTab ) => void ;
13
15
}
14
16
15
17
@singleton ( )
16
18
export class EditorController extends Controller implements IEditorController {
19
+ private editorInstance ;
20
+ // Group Pos locate here temporary, we can move it to state or localStorage if you need
21
+ public groupSplitPos : string [ ] = [ ] ;
22
+
23
+ constructor ( ) {
24
+ super ( ) ;
25
+ }
26
+
17
27
public onCloseAll = ( groupId : number ) => {
18
28
editorService . closeAll ( groupId ) ;
19
29
this . emit ( EditorEvent . OnCloseAll , groupId ) ;
@@ -34,12 +44,18 @@ export class EditorController extends Controller implements IEditorController {
34
44
} ;
35
45
36
46
public onSelectTab = ( tabKey : string , groupId : number ) => {
37
- editorService . updateCurrent ( groupId , tabKey ) ;
47
+ editorService . setActive ( groupId , tabKey ) ;
48
+ const { current } = editorService . getState ( ) ;
49
+ current ?. editorInstance . setValue ( current . tab ?. data . value ) ;
38
50
this . emit ( EditorEvent . OnSelectTab , tabKey , groupId ) ;
39
51
} ;
40
52
41
- public onUpdateEditorIns = ( editorInstance : any , groupId : number ) => {
53
+ public onUpdateEditorIns = (
54
+ editorInstance : IStandaloneCodeEditor ,
55
+ groupId : number
56
+ ) => {
42
57
if ( editorInstance ) {
58
+ this . initEditorEvents ( editorInstance , groupId ) ;
43
59
editorService . updateGroup ( groupId , {
44
60
editorInstance : editorInstance ,
45
61
} ) ;
@@ -50,4 +66,50 @@ export class EditorController extends Controller implements IEditorController {
50
66
editorService . cloneGroup ( ) ;
51
67
this . emit ( EditorEvent . OnSplitEditorRight ) ;
52
68
} ;
69
+
70
+ public onPaneSizeChange = ( newSize ) => {
71
+ this . groupSplitPos = newSize ;
72
+ } ;
73
+
74
+ public onTabContextMenu = ( e : React . MouseEvent , tab : IEditorTab ) => {
75
+ console . log ( 'onTabContextMenu' , e , tab ) ;
76
+ } ;
77
+
78
+ private initEditorEvents (
79
+ editorInstance : IStandaloneCodeEditor ,
80
+ groupId : number
81
+ ) {
82
+ this . editorInstance = editorInstance ;
83
+ if ( editorInstance ) {
84
+ editorInstance . onDidChangeModelContent ( ( event : any ) => {
85
+ const newValue = editorInstance . getValue ( ) ;
86
+ const { current } = editorService . getState ( ) ;
87
+ const tab = current ?. tab ;
88
+ if ( tab ) {
89
+ editorService . updateTab (
90
+ {
91
+ id : tab . id ,
92
+ data : {
93
+ ...tab . data ,
94
+ value : newValue ,
95
+ } ,
96
+ modified : true ,
97
+ } ,
98
+ groupId
99
+ ) ;
100
+ }
101
+ } ) ;
102
+
103
+ editorInstance . onDidFocusEditorText ( ( ) => {
104
+ const group = editorService . getGroupById ( groupId ) ;
105
+ if ( group ?. tab ! . id ) {
106
+ editorService . setActive ( groupId , group . tab . id ) ;
107
+ }
108
+ } ) ;
109
+ }
110
+ }
111
+
112
+ getEditorInstance ( ) {
113
+ return this . editorInstance ;
114
+ }
53
115
}
0 commit comments