From 3d1e09bc3cac65af5fd37080003089336dfb4310 Mon Sep 17 00:00:00 2001 From: Dennis Kehrig Date: Wed, 20 Feb 2013 12:43:22 +0100 Subject: [PATCH 1/2] Bugfix: directory renames were not propagated --- src/project/ProjectManager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/project/ProjectManager.js b/src/project/ProjectManager.js index d75989f9021..fb19839e472 100644 --- a/src/project/ProjectManager.js +++ b/src/project/ProjectManager.js @@ -1296,7 +1296,9 @@ define(function (require, exports, module) { } var oldName = selected.data("entry").fullPath; - var oldNameRegex = new RegExp(StringUtils.regexEscape(data.rslt.old_name) + "$"); + // Folder paths have to end with a slash. Use look-head (?=...) to only replace the folder's name, not the slash as well + var oldNameEndPattern = isFolder ? "(?=\/$)" : "$"; + var oldNameRegex = new RegExp(StringUtils.regexEscape(data.rslt.old_name) + oldNameEndPattern); var newName = oldName.replace(oldNameRegex, data.rslt.new_name); renameItem(oldName, newName, isFolder) From 2f45848c175c2e097c0377b0535ee9a7fbcbe3c1 Mon Sep 17 00:00:00 2001 From: Dennis Kehrig Date: Wed, 20 Feb 2013 13:27:59 +0100 Subject: [PATCH 2/2] Bugfix: renaming file "foo" should not affect file "foobar/baz" even though "foo" is a prefix of "foobar". --- src/document/DocumentManager.js | 8 ++++---- src/file/FileUtils.js | 23 ++++++++++++++++++++--- src/project/ProjectManager.js | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index 351dfde9b3e..03694ac50df 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -1156,7 +1156,7 @@ define(function (require, exports, module) { var keysToDelete = []; for (path in _openDocuments) { if (_openDocuments.hasOwnProperty(path)) { - if (path.indexOf(oldName) === 0) { + if (FileUtils.isAffectedWhenRenaming(path, oldName, newName, isFolder)) { // Copy value to new key var newKey = path.replace(oldName, newName); @@ -1164,8 +1164,8 @@ define(function (require, exports, module) { keysToDelete.push(path); // Update document file - FileUtils.updateFileEntryPath(_openDocuments[newKey].file, oldName, newName); - + FileUtils.updateFileEntryPath(_openDocuments[newKey].file, oldName, newName, isFolder); + if (!isFolder) { // If the path name is a file, there can only be one matched entry in the open document // list, which we just updated. Break out of the for .. in loop. @@ -1181,7 +1181,7 @@ define(function (require, exports, module) { // Update working set for (i = 0; i < _workingSet.length; i++) { - FileUtils.updateFileEntryPath(_workingSet[i], oldName, newName); + FileUtils.updateFileEntryPath(_workingSet[i], oldName, newName, isFolder); } // Send a "fileNameChanged" event. This will trigger the views to update. diff --git a/src/file/FileUtils.js b/src/file/FileUtils.js index 7892c557003..59d73ae8f25 100644 --- a/src/file/FileUtils.js +++ b/src/file/FileUtils.js @@ -248,14 +248,30 @@ define(function (require, exports, module) { } /** + * Checks wheter a path is affected by a rename operation. + * A path is affected if the object being renamed is a file and the given path refers + * to that file or if the object being renamed is a directory and a prefix of the path. + * Always checking for prefixes can create conflicts: + * renaming file "foo" should not affect file "foobar/baz" even though "foo" is a prefix of "foobar". + * @param {!string} path The path potentially affected + * @param {!string} oldName An object's name before renaming + * @param {!string} newName An object's name after renaming + * @param {?boolean} isFolder Whether the renamed object is a folder or not + */ + function isAffectedWhenRenaming(path, oldName, newName, isFolder) { + isFolder = isFolder || oldName.slice(-1) === "/"; + return (isFolder && path.indexOf(oldName) === 0) || (!isFolder && path === oldName); + } + + /** * Update a file entry path after a file/folder name change. * @param {FileEntry} entry The FileEntry or DirectoryEntry to update * @param {string} oldName The full path of the old name * @param {string} newName The full path of the new name * @return {boolean} Returns true if the file entry was updated */ - function updateFileEntryPath(entry, oldName, newName) { - if (entry.fullPath.indexOf(oldName) === 0) { + function updateFileEntryPath(entry, oldName, newName, isFolder) { + if (isAffectedWhenRenaming(entry.fullPath, oldName, newName, isFolder)) { var fullPath = entry.fullPath.replace(oldName, newName); entry.fullPath = fullPath; @@ -276,7 +292,7 @@ define(function (require, exports, module) { return false; } - + /** @const - hard-coded for now, but may want to make these preferences */ var _staticHtmlFileExts = ["htm", "html"], _serverHtmlFileExts = ["php", "php3", "php4", "php5", "phtm", "phtml", "cfm", "cfml", "asp", "aspx", "jsp", "jspx", "shtm", "shtml"]; @@ -327,6 +343,7 @@ define(function (require, exports, module) { exports.getNativeBracketsDirectoryPath = getNativeBracketsDirectoryPath; exports.getNativeModuleDirectoryPath = getNativeModuleDirectoryPath; exports.canonicalizeFolderPath = canonicalizeFolderPath; + exports.isAffectedWhenRenaming = isAffectedWhenRenaming; exports.updateFileEntryPath = updateFileEntryPath; exports.isStaticHtmlFileExt = isStaticHtmlFileExt; exports.isServerHtmlFileExt = isServerHtmlFileExt; diff --git a/src/project/ProjectManager.js b/src/project/ProjectManager.js index fb19839e472..b1f8863464a 100644 --- a/src/project/ProjectManager.js +++ b/src/project/ProjectManager.js @@ -1225,7 +1225,7 @@ define(function (require, exports, module) { for (i = 0; i < nodes.length; i++) { var node = $(nodes[i]); - FileUtils.updateFileEntryPath(node.data("entry"), oldName, newName); + FileUtils.updateFileEntryPath(node.data("entry"), oldName, newName, isFolder); } // Notify that one of the project files has changed