TfTHacker / obsidian42-text-transporter

Text Transporter - advanced text management for Obsidian.
https://tfthacker.com/transporter
MIT License
205 stars 10 forks source link

Copy block as alias keyboard shortcut does not work directly after pasting #74

Closed harpreetchima closed 7 months ago

harpreetchima commented 9 months ago

Nothing happens if you copy/paste text (in my case, a highlight from Zotero) and use the keyboard shortcut to copy the block as an alias. You must first click somewhere else in the paragraph or move the cursor before the keyboard shortcut will work.

TfTHacker commented 7 months ago

Thank you for reporting this issue. I am unable to replicate it. Could you please capture a quick screen recording (video) so I can see what is happening?

Additionally, does the same issue occur outside of a Zotero highlight?

harpreetchima commented 7 months ago

Looks like there is just a delay between creating a new line (pasting or typing) and the ^aliasID appearing when using the shortcut. Recording - 15 Apr 2024.webm

TfTHacker commented 7 months ago

Thank you for the recording. I attempted to replicate the delay, but I didn't observe any. I'm curious to know if the delay persists when you disable your other plugins, leaving only Text Transporter active. Generally, I would expect this to be fast, as there is no significant data processing involved.

harpreetchima commented 7 months ago

I disabled all my other plugins but still observed the same delay. This is practically a fresh windows install; not sure what it could be.

TfTHacker commented 7 months ago

Thank you for giving it a try. Upon a closer inspection, I believe I've identified the issue. Text Transporter relies on Obsidian’s cached version of a document to analyze the structure and context to determine both the cursor's position and whether or not the text already has a block. As you edit the text of a file, the cache is refreshed in the background, typically a second or two after you stop editing, though the timing is not guaranteed.

I managed to replicate your situation when pasting text because Obsidian may need a few seconds to cache the text and make it accessible to the API.

In summary, the problem isn't a bug but a delay resulting from Obsidian's method of processing file changes. This means that when you copy and paste text and then quickly try to create a block ID with an alias, the text hasn't yet been updated in the cache.

Therefore, after pasting, if you wait a second or two, you should be able to generate the alias to the block reference.

Additionally, performing an “undo” action can also result in a brief delay as the cache updates.