longform icon indicating copy to clipboard operation
longform copied to clipboard

Add option to `rename` scene to the context menu

Open chrisgrieser opened this issue 4 years ago • 5 comments

Similar to #16, only a rename option. The longform explorer is indeed more useful than the file explorer. But an option to rename scenes more easily is definitely missing.

chrisgrieser avatar Sep 15 '21 22:09 chrisgrieser

I'd considered this, but realized the editor itself allows renames. That said, I can add this feature--it does require a partial rewrite of the explorer, though.

kevboh avatar Sep 16 '21 11:09 kevboh

yeah; i realized I could also use the header bar. It's not really a must-have-feature, but it would be nice to have, since using the editor instead of the context menu for renaming breaks with the usual habits.

chrisgrieser avatar Sep 16 '21 11:09 chrisgrieser

This will be in 2.0.

kevboh avatar Aug 13 '22 11:08 kevboh

Hi @kevboh! Found a problem and a solution.

I noticed that renaming files from the Scene list didn't automatically update links. ("Updated X links in Y files").

Simple fix: in SceneList:

diff --git a/src/view/explorer/SceneList.svelte b/src/view/explorer/SceneList.svelte
index 4000ef8..3e7fdeb 100644
--- a/src/view/explorer/SceneList.svelte
+++ b/src/view/explorer/SceneList.svelte
@@ -195,7 +195,8 @@
         // Rename file
         const oldPath = scenePath(editingName, $selectedDraft, app.vault);
         const newPath = scenePath(newName, $selectedDraft, app.vault);
-        app.vault.adapter.rename(oldPath, newPath);
+        const file = app.vault.getAbstractFileByPath(oldPath);
+        app.fileManager.renameFile(file, newPath);
         editingName = null;
         return false;
       } else if (event.key === "Escape") {

This diff uses FileManager.renameFile - "Rename or move a file safely, and update all links to it depending on the user's preferences" (ref)

Notes

  • FileSystemAdapter.rename(path, newPath) (ref) is apparently just a thin-wrapper around OS file functions, and doesn't do the Obsidian link tracking magic.
  • Incidentally, there's also Vault.rename(file, newPath) (ref), which also refrains from updating links. (I did try it just to see what it would do 😅 )

p2edwards avatar Aug 24 '22 09:08 p2edwards

huh! had no idea, thanks. Really wish the APIs were documented....

kevboh avatar Aug 24 '22 14:08 kevboh

The "Rename" option in the context menu of Scenes list is not effectual for me. Clicking it merely closes the context menu. And then I am unable to open the context menu in Scenes list, until I restart Obsidian.

Should I report this as a separate issue?

wesleyboar avatar Jan 07 '24 08:01 wesleyboar

I think using this one is fine—thanks for flagging.

kevboh avatar Jan 19 '24 21:01 kevboh