Skip to content

Commit

Permalink
feat: delete unless code
Browse files Browse the repository at this point in the history
  • Loading branch information
mumiao committed Dec 18, 2020
1 parent fa829a7 commit be4091d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 43 deletions.
1 change: 0 additions & 1 deletion src/common/event/eventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class EventEmitter {
if (events && events.length > 0) {
// The log for development
events.forEach((callEvent) => {
console.log(...args)
callEvent(...args);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/tabs/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
height: 18px;
position: relative;
width: 18px;

&::after {
border-radius: 50%;
content: '';
Expand All @@ -76,15 +76,15 @@
width: 9px;
}
}

&__close {
cursor: pointer;
display: block;
font-weight: 500;
height: 18px;
width: 18px;
}

&__placeholder {
display: block;
height: 18px;
Expand Down
95 changes: 56 additions & 39 deletions src/services/workbench/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ export class EditorService

@emit(EditorEvent.OnSelectTab)
onSelectTab(callback: (tabKey: string) => void) {
this.subscribe(EditorEvent.OnSelectTab, (targetKey: string, groupId?: number) => {
let group;
let { groups } = this.state;
if (groupId === undefined) return;
group = groups?.find((group: IEditorGroup) => group.id === groupId);
group.activeTab = { ...group.activeTab, key: targetKey };
callback?.(targetKey);
});
this.subscribe(
EditorEvent.OnSelectTab,
(targetKey: string, groupId?: number) => {
let group;
let { groups } = this.state;
if (groupId === undefined) return;
group = groups?.find(
(group: IEditorGroup) => group.id === groupId
);
group.activeTab = { ...group.activeTab, key: targetKey };
callback?.(targetKey);
}
);
}

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

@emit(EditorEvent.OnMoveTab)
public onMoveTab(callback: (data) => void) {
this.subscribe(EditorEvent.OnMoveTab, (tabs: ITab[], groupId?: number) => {
let { groups } = this.state;
let group;
if (isEmpty(groupId)) return;
group = groups?.find((group: IEditorGroup) => group.id === groupId);
group.tabs = tabs;
callback?.(tabs);
});
this.subscribe(
EditorEvent.OnMoveTab,
(tabs: ITab[], groupId?: number) => {
let { groups } = this.state;
let group;
if (isEmpty(groupId)) return;
group = groups?.find(
(group: IEditorGroup) => group.id === groupId
);
group.tabs = tabs;
callback?.(tabs);
}
);
}
public closeAll() {}

@emit(EditorEvent.OnCloseTab)
public onCloseTab(callback: (data) => void) {
this.subscribe(EditorEvent.OnCloseTab, (targetKey: string, groupId?: number) => {
let group, lastIndex;
let { groups } = this.state;
if (groupId === undefined) return;
group = groups?.find((group: IEditorGroup) => group.id === groupId);
let newActiveKey = group?.activeTab?.key;
const groupTabs = group.tabs;
groupTabs.forEach((pane, i) => {
if (pane.key === targetKey) {
lastIndex = i - 1;
}
});
const newPanes = groupTabs.filter((pane) => pane.key !== targetKey);
if (newPanes.length && newActiveKey === targetKey) {
if (lastIndex >= 0) {
newActiveKey = newPanes[lastIndex].key;
} else {
newActiveKey = newPanes[0].key;
this.subscribe(
EditorEvent.OnCloseTab,
(targetKey: string, groupId?: number) => {
let group, lastIndex;
let { groups } = this.state;
if (groupId === undefined) return;
group = groups?.find(
(group: IEditorGroup) => group.id === groupId
);
let newActiveKey = group?.activeTab?.key;
const groupTabs = group.tabs;
groupTabs.forEach((pane, i) => {
if (pane.key === targetKey) {
lastIndex = i - 1;
}
});
const newPanes = groupTabs.filter(
(pane) => pane.key !== targetKey
);
if (newPanes.length && newActiveKey === targetKey) {
if (lastIndex >= 0) {
newActiveKey = newPanes[lastIndex].key;
} else {
newActiveKey = newPanes[0].key;
}
}
}
group.tabs = newPanes;
group.activeTab = { ...group.activeTab, key: newActiveKey };
group.tabs = newPanes;
group.activeTab = { ...group.activeTab, key: newActiveKey };

callback?.(targetKey);
});
callback?.(targetKey);
}
);
}
}

0 comments on commit be4091d

Please sign in to comment.