From 2c1aed4e8a26466dbd065fbb02edce850bbe8da8 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Thu, 18 Feb 2021 11:18:26 +0100 Subject: [PATCH] Rntabs (#893) This addresses an issue when you rename a folder which has files which are open in tabs. It would recreate the current opened file because it is current and saved when another file opened. You'd get duplicate files. Also tabs from the old folder would still be visible. Now the behavior should be: tabs that belong to the folder renamed will be closed and replaced. No file will be focused. Please test. --- apps/remix-ide/src/app/files/fileManager.js | 6 +--- apps/remix-ide/src/app/panels/tab-proxy.js | 32 ++++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 8e46839fcf..acb5712dca 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -300,20 +300,16 @@ class FileManager extends Plugin { } this.openFile(newName) } else { - var newFocus for (var k in this.openedFiles) { if (k.indexOf(oldName + '/') === 0) { var newAbsolutePath = k.replace(oldName, newName) this.openedFiles[newAbsolutePath] = newAbsolutePath delete this.openedFiles[k] if (this._deps.config.get('currentFile') === k) { - newFocus = newAbsolutePath + this._deps.config.set('currentFile', '') } } } - if (newFocus) { - this.openFile(newFocus) - } } // TODO: Only keep `this.emit` (issue#2210) this.emit('fileRenamed', oldName, newName, isFolder) diff --git a/apps/remix-ide/src/app/panels/tab-proxy.js b/apps/remix-ide/src/app/panels/tab-proxy.js index dc571258e4..e1bf88a33b 100644 --- a/apps/remix-ide/src/app/panels/tab-proxy.js +++ b/apps/remix-ide/src/app/panels/tab-proxy.js @@ -60,17 +60,17 @@ export class TabProxy extends Plugin { }) fileManager.events.on('fileRenamed', (oldName, newName, isFolder) => { - if (isFolder) return + if (isFolder) { + for (const tab of this.loadedTabs) { + if (tab.name.indexOf(oldName + '/') === 0) { + const newTabName = newName + tab.name.slice(oldName.length, tab.name.length) + this.renameTab(tab.name, newTabName) + } + } + return + } // should change the tab title too - this.addTab(newName, '', () => { - this.fileManager.open(newName) - this.event.emit('openFile', newName) - }, - () => { - this.fileManager.closeFile(newName) - this.event.emit('closeFile', newName) - }) - this.removeTab(oldName) + this.renameTab(oldName, newName) }) appManager.event.on('activate', ({ name, location, displayName, icon }) => { @@ -144,6 +144,18 @@ export class TabProxy extends Plugin { } } + renameTab (oldName, newName) { + this.addTab(newName, '', () => { + this.fileManager.open(newName) + this.event.emit('openFile', newName) + }, + () => { + this.fileManager.closeFile(newName) + this.event.emit('closeFile', newName) + }) + this.removeTab(oldName) + } + addTab (name, title, switchTo, close, icon) { if (this._handlers[name]) return