GitMurf / obsidian-drag-and-drop-blocks

Drag and Drop blocks to move, copy and create block references.
81 stars 6 forks source link

relative reference to source file will result in unpredictable behaviour in case the same file name exists in different folders #9

Open zsviczian opened 3 years ago

zsviczian commented 3 years ago

Instead of the base filename, I would suggest including the entire file path, or at least offer it as an option. https://github.com/GitMurf/obsidian-drag-and-drop-blocks/blob/2caec7be6011db3fadd368aef39a99891b7add87/main.ts#L686

Demo

Fail scenario

Because Obsidian's find nearest file resolves to Test 1/Source.md

demo

Success scenario

For the same reason as above

demo

Suggested solution

Consider using file.path instead when setting the dataTransfer item, I guess here:

https://github.com/GitMurf/obsidian-drag-and-drop-blocks/blob/2caec7be6011db3fadd368aef39a99891b7add87/main.ts#L701

Then in this function

https://github.com/GitMurf/obsidian-drag-and-drop-blocks/blob/2caec7be6011db3fadd368aef39a99891b7add87/main.ts#L741

You could use the following code to get the right relative filepath: this.app.metadataCache.fileToLinktext(mdView2.file,mdView.file.path,true) You will of course need to move up the declaration of mdView2...

GitMurf commented 3 years ago

Thanks! It was on my list of things to fix but I was too lazy ;) this helps a lot and makes it clear/simple. I’ll add a setting to choose if you want full paths and then fix how the link is created with the suggestions above.