@@ -36,14 +36,19 @@ export class EditorService
36
36
37
37
@emit ( EditorEvent . OnSelectTab )
38
38
onSelectTab ( callback : ( tabKey : string ) => void ) {
39
- this . subscribe ( EditorEvent . OnSelectTab , ( targetKey : string , groupId ?: number ) => {
40
- let group ;
41
- let { groups } = this . state ;
42
- if ( groupId === undefined ) return ;
43
- group = groups ?. find ( ( group : IEditorGroup ) => group . id === groupId ) ;
44
- group . activeTab = { ...group . activeTab , key : targetKey } ;
45
- callback ?.( targetKey ) ;
46
- } ) ;
39
+ this . subscribe (
40
+ EditorEvent . OnSelectTab ,
41
+ ( targetKey : string , groupId ?: number ) => {
42
+ let group ;
43
+ let { groups } = this . state ;
44
+ if ( groupId === undefined ) return ;
45
+ group = groups ?. find (
46
+ ( group : IEditorGroup ) => group . id === groupId
47
+ ) ;
48
+ group . activeTab = { ...group . activeTab , key : targetKey } ;
49
+ callback ?.( targetKey ) ;
50
+ }
51
+ ) ;
47
52
}
48
53
49
54
@emit ( EditorEvent . OpenTab )
@@ -65,43 +70,55 @@ export class EditorService
65
70
66
71
@emit ( EditorEvent . OnMoveTab )
67
72
public onMoveTab ( callback : ( data ) => void ) {
68
- this . subscribe ( EditorEvent . OnMoveTab , ( tabs : ITab [ ] , groupId ?: number ) => {
69
- let { groups } = this . state ;
70
- let group ;
71
- if ( isEmpty ( groupId ) ) return ;
72
- group = groups ?. find ( ( group : IEditorGroup ) => group . id === groupId ) ;
73
- group . tabs = tabs ;
74
- callback ?.( tabs ) ;
75
- } ) ;
73
+ this . subscribe (
74
+ EditorEvent . OnMoveTab ,
75
+ ( tabs : ITab [ ] , groupId ?: number ) => {
76
+ let { groups } = this . state ;
77
+ let group ;
78
+ if ( isEmpty ( groupId ) ) return ;
79
+ group = groups ?. find (
80
+ ( group : IEditorGroup ) => group . id === groupId
81
+ ) ;
82
+ group . tabs = tabs ;
83
+ callback ?.( tabs ) ;
84
+ }
85
+ ) ;
76
86
}
77
87
public closeAll ( ) { }
78
88
79
89
@emit ( EditorEvent . OnCloseTab )
80
90
public onCloseTab ( callback : ( data ) => void ) {
81
- this . subscribe ( EditorEvent . OnCloseTab , ( targetKey : string , groupId ?: number ) => {
82
- let group , lastIndex ;
83
- let { groups } = this . state ;
84
- if ( groupId === undefined ) return ;
85
- group = groups ?. find ( ( group : IEditorGroup ) => group . id === groupId ) ;
86
- let newActiveKey = group ?. activeTab ?. key ;
87
- const groupTabs = group . tabs ;
88
- groupTabs . forEach ( ( pane , i ) => {
89
- if ( pane . key === targetKey ) {
90
- lastIndex = i - 1 ;
91
- }
92
- } ) ;
93
- const newPanes = groupTabs . filter ( ( pane ) => pane . key !== targetKey ) ;
94
- if ( newPanes . length && newActiveKey === targetKey ) {
95
- if ( lastIndex >= 0 ) {
96
- newActiveKey = newPanes [ lastIndex ] . key ;
97
- } else {
98
- newActiveKey = newPanes [ 0 ] . key ;
91
+ this . subscribe (
92
+ EditorEvent . OnCloseTab ,
93
+ ( targetKey : string , groupId ?: number ) => {
94
+ let group , lastIndex ;
95
+ let { groups } = this . state ;
96
+ if ( groupId === undefined ) return ;
97
+ group = groups ?. find (
98
+ ( group : IEditorGroup ) => group . id === groupId
99
+ ) ;
100
+ let newActiveKey = group ?. activeTab ?. key ;
101
+ const groupTabs = group . tabs ;
102
+ groupTabs . forEach ( ( pane , i ) => {
103
+ if ( pane . key === targetKey ) {
104
+ lastIndex = i - 1 ;
105
+ }
106
+ } ) ;
107
+ const newPanes = groupTabs . filter (
108
+ ( pane ) => pane . key !== targetKey
109
+ ) ;
110
+ if ( newPanes . length && newActiveKey === targetKey ) {
111
+ if ( lastIndex >= 0 ) {
112
+ newActiveKey = newPanes [ lastIndex ] . key ;
113
+ } else {
114
+ newActiveKey = newPanes [ 0 ] . key ;
115
+ }
99
116
}
100
- }
101
- group . tabs = newPanes ;
102
- group . activeTab = { ...group . activeTab , key : newActiveKey } ;
117
+ group . tabs = newPanes ;
118
+ group . activeTab = { ...group . activeTab , key : newActiveKey } ;
103
119
104
- callback ?.( targetKey ) ;
105
- } ) ;
120
+ callback ?.( targetKey ) ;
121
+ }
122
+ ) ;
106
123
}
107
124
}
0 commit comments