zolrath / obsidian-auto-link-title

Automatically fetch the titles of pasted links
MIT License
415 stars 55 forks source link

Pasting on iOS inconsitent #120

Open cdloh opened 3 weeks ago

cdloh commented 3 weeks ago

Hi love the plugin and regularlly use it but for some reason it's super inconsistent on iOS and for the life of me I can't figure out why. I've tracked a few things down and will note them below

  1. clipboardData.getData("text/plain"); is null or blank string sometimes I can't figure out why this is but swapping to navigator.clipboard.readText() fixes this and is always consistent. However if we await on the readText here it then causes the text to get over ridden on selection :( 

Steps to reproduce this

  1. Open safari and browser to a URL

  2. Click Share and then Copy

  3. Open Obsidian and Paste into a note

  4. Pasting a link appears to automatically parse it into a URL causing the shouldPreserveSelectionAsTitle option to trigger even though before the paste event we didn't have anything selected Adding a check to see if the selected text is the same as the paste text fixes this

if (selectedText && this.settings.shouldPreserveSelectionAsTitle && selectedText != clipboardText) {
                editor.replaceSelection(`[${selectedText}](${clipboardText})`);
                return;
            }

It's worth noting that sometimes this isn't even an issue! I don't know what causes the inconsistency at all. For example if I copy a URL within obsidian and then paste it again the clipboardData is consistent.

byarbrough commented 1 week ago

On my iPhone the title is properly fetched from Safari if I tap the URL and copy, but not if I do Share>Copy. Note that I get the "Allow copy" warning which might be part of the problem. Either way works with Firefox.

stevedoyle commented 3 days ago

On my iPhone the title is properly fetched from Safari if I tap the URL and copy, but not if I do Share>Copy.

Same on my iPhone and iPad.