(tabId: UniqueId, groupId: UniqueId)
| 401 | } |
| 402 | |
| 403 | public closeTab(tabId: UniqueId, groupId: UniqueId) { |
| 404 | const groupIndex = this.getGroupIndexById(groupId); |
| 405 | if (groupIndex === -1) return; |
| 406 | |
| 407 | const { groups = [] } = this.state; |
| 408 | const nextGroups = [...groups]; |
| 409 | const nextGroup = nextGroups[groupIndex]; |
| 410 | const tabIndex = nextGroup.data!.findIndex(searchById(tabId)); |
| 411 | |
| 412 | const tab = cloneDeep(nextGroup.data![tabIndex]); |
| 413 | if (tabIndex === -1) return; |
| 414 | |
| 415 | if (nextGroup.data!.length === 1 && tabIndex === 0) { |
| 416 | // the tab which is closing is the only one tab in current group, |
| 417 | // so delete group and choose last or former group as current one |
| 418 | const activeGroup = |
| 419 | nextGroups[groupIndex + 1] || nextGroups[groupIndex - 1]; |
| 420 | |
| 421 | nextGroups.splice(groupIndex, 1); |
| 422 | |
| 423 | this.setState( |
| 424 | { |
| 425 | groups: nextGroups, |
| 426 | current: nextGroups?.length === 0 ? undefined : activeGroup, |
| 427 | }, |
| 428 | () => { |
| 429 | const isOpened = this.isOpened(tabId); |
| 430 | // the model of closed tab should be disposed after closing |
| 431 | !isOpened && this.disposeModel(tab); |
| 432 | this.explorerService.forceUpdate(); |
| 433 | } |
| 434 | ); |
| 435 | // reset the editor group |
| 436 | this.layoutService.setGroupSplitSize( |
| 437 | nextGroups.length |
| 438 | ? new Array(nextGroups.length + 1).fill('auto') |
| 439 | : [] |
| 440 | ); |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | if (tabId === nextGroup.activeTab) { |
| 445 | // the tab which is closing is the active one, |
| 446 | // then choose last or former tab as current one |
| 447 | const nextTab = |
| 448 | nextGroup.data![tabIndex + 1] || nextGroup.data![tabIndex - 1]; |
| 449 | nextGroup.tab = { ...nextTab }; |
| 450 | nextGroup.activeTab = nextTab?.id; |
| 451 | } |
| 452 | |
| 453 | nextGroup.data!.splice(tabIndex, 1); |
| 454 | nextGroups[groupIndex] = nextGroup; |
| 455 | |
| 456 | this.setState( |
| 457 | { |
| 458 | current: nextGroup, |
| 459 | groups: nextGroups, |
| 460 | }, |
nothing calls this directly
no test coverage detected