@@ -26,11 +26,19 @@ export interface IEditorService extends Component<IEditor> {
26
26
tabId : string ,
27
27
group : IEditorGroup
28
28
) : IEditorTab < T > | undefined ;
29
- updateTab ( tab : IEditorTab , groupId : number ) : IEditorTab ;
29
+ /**
30
+ *
31
+ * @param groupId If not provided, molecule will update in all group
32
+ */
33
+ updateTab ( tab : IEditorTab , groupId ?: number ) : IEditorTab ;
30
34
/**
31
35
* Specify a entry page for editor
32
36
*/
33
37
setEntry ( component : React . ReactNode ) : void ;
38
+ /**
39
+ * Returns whether a specific tab exists
40
+ */
41
+ isOpened ( tabId : string ) : boolean ;
34
42
closeTab ( tabId : string , groupId : number ) : void ;
35
43
closeOthers ( tab : IEditorTab , groupId : number ) : void ;
36
44
closeToRight ( tab : IEditorTab , groupId : number ) : void ;
@@ -91,6 +99,11 @@ export class EditorService
91
99
} ) ;
92
100
}
93
101
102
+ public isOpened ( tabId : string ) : boolean {
103
+ const { groups = [ ] } = this . state ;
104
+ return groups . some ( ( group ) => this . getTabById ( tabId , group ) ) ;
105
+ }
106
+
94
107
public updateGroupActions ( actions : IMenuItemProps [ ] ) : void {
95
108
this . groupActions = actions ;
96
109
}
@@ -112,24 +125,47 @@ export class EditorService
112
125
return this . state . current ?. editorInstance ;
113
126
}
114
127
115
- public updateTab ( tab : IEditorTab , groupId : number ) : IEditorTab {
116
- const { groups = [ ] } = this . state ;
117
- const index = this . getGroupIndexById ( groupId ) ;
128
+ public updateTab ( tab : IEditorTab , groupId ? : number ) : IEditorTab {
129
+ if ( groupId ) {
130
+ const group = this . getGroupById ( groupId ) ;
118
131
119
- if ( index > - 1 ) {
120
- const group = groups [ index ] ;
132
+ if ( group ?. data ?. length ) {
133
+ const tabData = group . data . find ( searchById ( tab . id ) ) ;
121
134
122
- if ( group . data && group . data . length > 0 ) {
123
- const tabIndex = group . data ! . findIndex ( searchById ( tab . id ) ) ;
135
+ if ( tabData ) {
136
+ Object . assign ( tabData , tab ) ;
137
+ }
124
138
125
- if ( tabIndex > - 1 ) {
126
- const tabData = group . data ! [ tabIndex ] ;
127
- const newTab = Object . assign ( { } , tabData , tab ) ;
128
- group . data ! [ tabIndex ] = newTab ;
139
+ if ( group . activeTab === tab . id ) {
140
+ Object . assign ( group . tab , tab ) ;
141
+ }
142
+ this . updateGroup ( groupId , group ) ;
129
143
130
- this . render ( ) ;
144
+ if ( groupId === this . state . current ?. id ) {
145
+ this . updateCurrentGroup ( group ) ;
131
146
}
132
147
}
148
+ } else {
149
+ const { groups = [ ] , current } = this . state ;
150
+ groups . forEach ( ( group ) => {
151
+ const tabData = this . getTabById ( tab . id ! , group ) ;
152
+ if ( tabData ) {
153
+ Object . assign ( tabData , tab ) ;
154
+ }
155
+
156
+ if ( group . activeTab === tab . id ) {
157
+ Object . assign ( group . tab , tab ) ;
158
+ }
159
+ } ) ;
160
+
161
+ if ( current ?. activeTab === tab . id ) {
162
+ Object . assign ( current ! . tab , tab ) ;
163
+ }
164
+
165
+ this . setState ( {
166
+ current,
167
+ groups,
168
+ } ) ;
133
169
}
134
170
return tab ;
135
171
}
0 commit comments