From 11eabc8a978bc6e46177a209db31c32ecbf7194b Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 29 Apr 2022 17:31:04 +0530 Subject: [PATCH] current file fixed after deletion --- apps/remix-ide/src/app/files/fileManager.ts | 2 +- apps/remix-ide/src/app/panels/tab-proxy.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index d9e043fa67..aa02851c3e 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -600,7 +600,7 @@ class FileManager extends Plugin { // TODO: Only keep `this.emit` (issue#2210) this.emit('fileRemoved', path) this.events.emit('fileRemoved', path) - this.openFile() + this.openFile(this._deps.config.get('currentFile')) } async unselectCurrentFile() { diff --git a/apps/remix-ide/src/app/panels/tab-proxy.js b/apps/remix-ide/src/app/panels/tab-proxy.js index 7e4ce18a22..357f7d5cd1 100644 --- a/apps/remix-ide/src/app/panels/tab-proxy.js +++ b/apps/remix-ide/src/app/panels/tab-proxy.js @@ -41,6 +41,13 @@ export class TabProxy extends Plugin { if (this.fileManager.mode === 'browser') { name = name.startsWith(workspace + '/') ? name : workspace + '/' + name + // If deleted file is not current file and not an active tab in editor, + // ensure current file is active in the editor + if (this.fileManager.currentFile() && name !== this.fileManager.currentFile()) { + const currentFile = this.fileManager.currentFile() + const currentFileTabPath = currentFile.startsWith(workspace + '/') ? currentFile : workspace + '/' + currentFile + this.removeTab(name, { name: currentFileTabPath }) + } this.removeTab(name) } else { name = name.startsWith(this.fileManager.mode + '/') ? name : this.fileManager.mode + '/' + name @@ -261,11 +268,11 @@ export class TabProxy extends Plugin { this._handlers[name] = { switchTo, close } } - removeTab (name) { + removeTab (name, currentFileTab) { delete this._handlers[name] - let previous = null + let previous = currentFileTab this.loadedTabs = this.loadedTabs.filter((tab, index) => { - if (tab.name === name) previous = this.loadedTabs[index - 1] + if (!previous && tab.name === name) previous = this.loadedTabs[index - 1] return tab.name !== name }) this.renderComponent()