abo-abo / org-download

Drag and drop images to Emacs org-mode
1.07k stars 78 forks source link

Renaming attached images moves them to the wrong directory #209

Open gsingh93 opened 1 year ago

gsingh93 commented 1 year ago

When org-download-method is set to attach, the download file is placed in a subdirectory of org-attach-id-dir, where the node ID is used as the subdirectory path. For example, create an empty org file, copy the following URL to your clipboard, and then run M-x org-download-yank: https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png

The buffer will now look like this (but with a different ID):

#+DOWNLOADED: https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png @ 2023-05-31 15:08:20
[[attachment:data/BD/A97238-B45D-4FA1-82EE-DC2523033886/2023-05-31_15-08-20_Example.png]]
:PROPERTIES:
:ID:       BDA97238-B45D-4FA1-82EE-DC2523033886
:END:

Now run M-x org-download-rename-last-file and replace the name with "foo" and hit enter. The buffer will now look like this:

#+DOWNLOADED: https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png @ 2023-05-31 15:08:20
[[attachment:data/BD/A97238-B45D-4FA1-82EE-DC2523033886/foo.png]]
:PROPERTIES:
:ID:       BDA97238-B45D-4FA1-82EE-DC2523033886
:END:

But this link is now broken, as the image no longer exists at that location. It's been moved relative to the org file itself. If you add a link like [[file:./foo.png]], that will point to the file.

I believe the intended behavior should be that only the filename should change, not the directory. In this example, "./foo.png" should not have been created, but "data/BD/A97238-B45D-4FA1-82EE-DC2523033886/foo.png" should have been created.