Commit 645ea255 authored by gxkai's avatar gxkai

fix: 文件删除和tab切换联动

parent 68d82685
...@@ -167,6 +167,10 @@ export class TabProxy extends Plugin { ...@@ -167,6 +167,10 @@ export class TabProxy extends Plugin {
} }
} }
clearTab () {
this.tabsApi.activateTab('')
}
switchNextTab () { switchNextTab () {
const active = this.tabsApi.active() const active = this.tabsApi.active()
if (active && this._handlers[active]) { if (active && this._handlers[active]) {
...@@ -270,8 +274,19 @@ export class TabProxy extends Plugin { ...@@ -270,8 +274,19 @@ export class TabProxy extends Plugin {
} }
removeTab (name) { removeTab (name) {
const i = this.loadedTabs.findIndex(tab => tab.name === name)
if (name === this.tabsApi.active()) {
if (i > 0) {
this.switchPreviousTab()
} else if (i === 0 && this.loadedTabs.length > 1) {
this.switchNextTab()
} else {
this.clearTab()
}
delete this._handlers[name] delete this._handlers[name]
} else {
this.switchToActiveTab() this.switchToActiveTab()
}
this.loadedTabs = this.loadedTabs.filter(tab => tab.name !== name) this.loadedTabs = this.loadedTabs.filter(tab => tab.name !== name)
this.renderComponent() this.renderComponent()
this.updateImgStyles() this.updateImgStyles()
...@@ -294,6 +309,10 @@ export class TabProxy extends Plugin { ...@@ -294,6 +309,10 @@ export class TabProxy extends Plugin {
if (this.loadedTabs[index]) { if (this.loadedTabs[index]) {
const name = this.loadedTabs[index].name const name = this.loadedTabs[index].name
if (this._handlers[name]) this._handlers[name].close() if (this._handlers[name]) this._handlers[name].close()
if (index - 1 >= 0) {
onSelect(index - 1)
return
}
this.event.emit('tabCountChanged', this.loadedTabs.length) this.event.emit('tabCountChanged', this.loadedTabs.length)
} }
} }
...@@ -302,7 +321,6 @@ export class TabProxy extends Plugin { ...@@ -302,7 +321,6 @@ export class TabProxy extends Plugin {
const onZoomOut = () => this.editor.editorFontSize(-1) const onZoomOut = () => this.editor.editorFontSize(-1)
const onReady = (api) => { this.tabsApi = api } const onReady = (api) => { this.tabsApi = api }
ReactDOM.render( ReactDOM.render(
<TabsUI tabs={this.loadedTabs} onSelect={onSelect} onClose={onClose} onZoomIn={onZoomIn} onZoomOut={onZoomOut} onReady={onReady} /> <TabsUI tabs={this.loadedTabs} onSelect={onSelect} onClose={onClose} onZoomIn={onZoomIn} onZoomOut={onZoomOut} onReady={onReady} />
, this.el) , this.el)
......
...@@ -294,7 +294,6 @@ export const createNewFolder = async (path: string, rootDir: string) => { ...@@ -294,7 +294,6 @@ export const createNewFolder = async (path: string, rootDir: string) => {
export const deletePath = async (path: string[]) => { export const deletePath = async (path: string[]) => {
const fileManager = plugin.fileManager const fileManager = plugin.fileManager
for (const p of path) { for (const p of path) {
try { try {
await fileManager.remove(p) await fileManager.remove(p)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment