Skip to content

Commit be4091d

Browse files
committed
feat: delete unless code
1 parent fa829a7 commit be4091d

File tree

3 files changed

+59
-43
lines changed

3 files changed

+59
-43
lines changed

src/common/event/eventEmitter.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export class EventEmitter {
66
if (events && events.length > 0) {
77
// The log for development
88
events.forEach((callEvent) => {
9-
console.log(...args)
109
callEvent(...args);
1110
});
1211
}

src/components/tabs/style.scss

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
height: 18px;
6565
position: relative;
6666
width: 18px;
67-
67+
6868
&::after {
6969
border-radius: 50%;
7070
content: '';
@@ -76,15 +76,15 @@
7676
width: 9px;
7777
}
7878
}
79-
79+
8080
&__close {
8181
cursor: pointer;
8282
display: block;
8383
font-weight: 500;
8484
height: 18px;
8585
width: 18px;
8686
}
87-
87+
8888
&__placeholder {
8989
display: block;
9090
height: 18px;

src/services/workbench/editorService.ts

+56-39
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ export class EditorService
3636

3737
@emit(EditorEvent.OnSelectTab)
3838
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+
);
4752
}
4853

4954
@emit(EditorEvent.OpenTab)
@@ -65,43 +70,55 @@ export class EditorService
6570

6671
@emit(EditorEvent.OnMoveTab)
6772
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+
);
7686
}
7787
public closeAll() {}
7888

7989
@emit(EditorEvent.OnCloseTab)
8090
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+
}
99116
}
100-
}
101-
group.tabs = newPanes;
102-
group.activeTab = { ...group.activeTab, key: newActiveKey };
117+
group.tabs = newPanes;
118+
group.activeTab = { ...group.activeTab, key: newActiveKey };
103119

104-
callback?.(targetKey);
105-
});
120+
callback?.(targetKey);
121+
}
122+
);
106123
}
107124
}

0 commit comments

Comments
 (0)