kevboh / longform

A plugin for Obsidian that helps you write and edit novels, screenplays, and other long projects.
Other
651 stars 32 forks source link

Add option to `rename` scene to the context menu #24

Closed chrisgrieser closed 8 months ago

chrisgrieser commented 3 years ago

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.

kevboh commented 3 years ago

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.

chrisgrieser commented 3 years ago

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.

kevboh commented 2 years ago

This will be in 2.0.

p2edwards commented 2 years ago

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

kevboh commented 2 years ago

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

wesleyboar commented 8 months ago

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?

kevboh commented 8 months ago

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