MCPcopy Create free account
hub / github.com/DTStack/molecule / open

Method open

src/services/workbench/editorService.ts:642–686  ·  view source on GitHub ↗

* @param groupId If provided, will open tab in specific group

(tab: IEditorTab<T>, groupId?: UniqueId)

Source from the content-addressed store, hash-verified

640 * @param groupId If provided, will open tab in specific group
641 */
642 public open<T>(tab: IEditorTab<T>, groupId?: UniqueId) {
643 const { current, groups = [] } = this.state;
644 let group = current;
645
646 if (groupId) {
647 // find specific group
648 group = this.getGroupById(groupId);
649 }
650
651 if (group) {
652 // insert tab into group
653 const { id: tabId } = tab;
654 const isExist = group?.data!.find(searchById(tabId));
655 if (isExist && tabId === group?.activeTab) return;
656
657 const groupIndex = this.getGroupIndexById(group.id!);
658 const currentGroup = groups[groupIndex];
659 if (!isExist) {
660 group.data!.push(tab);
661 }
662
663 group.tab = tab;
664 group.activeTab = tabId;
665 groups[groupIndex] = { ...currentGroup, tab, activeTab: tabId };
666 } else {
667 // if group isn't exist, open a new group
668 group = new EditorGroupModel(
669 groups.length + 1,
670 tab,
671 tab.id,
672 [tab],
673 this.defaultActions,
674 this.defaultMenus
675 );
676 groups.push(group);
677 }
678
679 this.emit(EditorEvent.OpenTab, tab);
680
681 this.setState({
682 current: group,
683 groups: [...groups],
684 });
685 this.explorerService.forceUpdate();
686 }
687
688 public onOpenTab(callback: (tab: IEditorTab) => void): void {
689 this.subscribe(EditorEvent.OpenTab, callback);

Callers

nothing calls this directly

Calls 6

getGroupByIdMethod · 0.95
getGroupIndexByIdMethod · 0.95
searchByIdFunction · 0.90
emitMethod · 0.80
setStateMethod · 0.80
forceUpdateMethod · 0.80

Tested by

no test coverage detected