make sure tabs are correctly closed

pull/1715/head
yann300 3 years ago
parent d751e25816
commit 51c689436c
  1. 15
      apps/remix-ide/src/app/panels/tab-proxy.js
  2. 5
      libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

@ -191,13 +191,6 @@ export class TabProxy extends Plugin {
} }
} }
switchToActiveTab () {
const active = this.tabsApi.active()
if (active && this._handlers[active]) {
this.switchTab(active)
}
}
renameTab (oldName, newName) { renameTab (oldName, newName) {
this.addTab(newName, '', () => { this.addTab(newName, '', () => {
this.fileManager.open(newName) this.fileManager.open(newName)
@ -271,10 +264,14 @@ export class TabProxy extends Plugin {
removeTab (name) { removeTab (name) {
delete this._handlers[name] delete this._handlers[name]
this.switchToActiveTab() let previous = null
this.loadedTabs = this.loadedTabs.filter(tab => tab.name !== name) this.loadedTabs = this.loadedTabs.filter((tab, index) => {
if (tab.name === name) previous = this.loadedTabs[index - 1]
return tab.name !== name
})
this.renderComponent() this.renderComponent()
this.updateImgStyles() this.updateImgStyles()
if (previous) this.switchTab(previous.name)
} }
addHandler (type, fn) { addHandler (type, fn) {

@ -35,10 +35,10 @@ export const TabsUI = (props: TabsUIProps) => {
const classNameImg = 'my-1 mr-1 text-dark ' + tab.iconClass const classNameImg = 'my-1 mr-1 text-dark ' + tab.iconClass
const classNameTab = 'nav-item nav-link d-flex justify-content-center align-items-center px-2 py-1 tab' + (index === currentIndexRef.current ? ' active' : '') const classNameTab = 'nav-item nav-link d-flex justify-content-center align-items-center px-2 py-1 tab' + (index === currentIndexRef.current ? ' active' : '')
return ( return (
<div ref={el => { tabsRef.current[index] = el }} className={classNameTab} title={tab.tooltip}> <div onClick={() => { props.onSelect(index); currentIndexRef.current = index; setSelectedIndex(index); }} ref={el => { tabsRef.current[index] = el }} className={classNameTab} title={tab.tooltip}>
{tab.icon ? (<img className="my-1 mr-1 iconImage" src={tab.icon} />) : (<i className={classNameImg}></i>)} {tab.icon ? (<img className="my-1 mr-1 iconImage" src={tab.icon} />) : (<i className={classNameImg}></i>)}
<span className="title-tabs">{tab.title}</span> <span className="title-tabs">{tab.title}</span>
<span className="close-tabs" onClick={() => props.onClose(index)}> <span className="close-tabs" onClick={(event) => { props.onClose(index); event.stopPropagation(); }}>
<i className="text-dark fas fa-times"></i> <i className="text-dark fas fa-times"></i>
</span> </span>
</div> </div>
@ -71,7 +71,6 @@ export const TabsUI = (props: TabsUIProps) => {
<Tabs <Tabs
className="tab-scroll" className="tab-scroll"
selectedIndex={selectedIndex} selectedIndex={selectedIndex}
onSelect={index => { props.onSelect(index); currentIndexRef.current = index; setSelectedIndex(index) }}
> >
<TabList className="d-flex flex-row justify-content-center align-items-center"> <TabList className="d-flex flex-row justify-content-center align-items-center">
{props.tabs.map((tab, i) => <Tab className="py-1" key={tab.name}>{renderTab(tab, i)}</Tab>)} {props.tabs.map((tab, i) => <Tab className="py-1" key={tab.name}>{renderTab(tab, i)}</Tab>)}

Loading…
Cancel
Save