denolehov/obsidian-url-into-selection

Don't override standard ctrl+v functionality

Opened this issue Β· 18 comments

Mpic commented

This plugin is awesome as it implements one of my preferred Typora's functionalities : automatic handling of URL pasting.
I love being able to copy a URL, select some text (or not if I just want one word) then ctrl+K to automagically make a perfect Markdown link.

However, I really don't want to use ctrl+v for that, and this plugin even though I set a hotkey to ctrl+k continues to override ctrl+v and it shows each time I paste something that is detected wrongfully or not as an URL : as an example, pasting <% tp.file.cursor() %> anywhere gives [](<%3C% tp.file.cursor() %%3E>) and using shift+ctrl+v doesn't bypass this, so I have to either manually delete all the junk added by the plugin or stop using the plugin :'(

Please, just use the hotkey setting to activate the plugin !

Hey @Mpic, I am unable to reproduce the issue with <%3C% tp.file.cursor() %%3E> string :(

Could you please make sure that you have the following regex specified in settings?

^[a-z0-9-]+:(\/){2,3}[a-zA-Z0-9-]+

If it's the only issue you're experiencing with the ctrl+v shortcut, I don't see a reason to kill it from plugin.

But I agree, ideally, the plugin should disable the ctrl+v shortcut if a custom one was specified in settings because the former one becomes redundant.

Mpic commented

Thanks !
It's not the only issue, that was just the latest example of a pasted text being misinterpreted by the plugin =/
It happens a lot with long texts copied from the web.
I can however confirm that the regex was not what you pasted, it was this instead (I think it was the default ?) :

[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)

The one you gave works better.

Still, it really would be nice to leave ctrl+v alone especially if another hotkey was specified.

Yeah I would also like to prevent the plugin from hijacking ctrl+v. Sometimes I want to paste a link without using the plugin (ie. I just want a raw url). I am also accustomed to being able to make a text selection and to then paste over it with ctrl+v. Here's the problem: Sometimes I want to paste a raw url over a selection and can't do so because of this issue. This has happened often enough that I came here to open an issue, only to discover someone else had me beat.

Mpic commented

I would also argue that a better default hotkey would be ctrl+k, as it is quite a standard one for inserting an URL in a selected text (here on GitHub, in your mail client, in Microsoft Word, in Typora, most smart text editors).

I have mine set to ctrl+shift+K leaving ctrl+k for Obsidian's default add markdown link behaviour.

Mpic commented

I have mine set to ctrl+shift+K leaving ctrl+k for Obsidian's default add markdown link behaviour.

I have found that I don’t need the default add markdown link as this plugin implements its functionality.

Yes, even if I choose 3.14, paste 2, it will become [2](3.14), so it's really annoying me.

I think it's necessary to judge whether the chosen or copied content is a URL before changing the pasting action.

Cito commented

Right. Either we use a dedicated hotkey for pasting URLs or we use the same hotkey ctrl-v, but then it should be checked whether it's really a URL. Also, if you are already inside a link construct, i.e. [...](...), then pasting should not create another, nested link construct, but change the URL in the already existing link.

Thought maybe a video demonstrating the issue might be helpful?

Screen.Recording.2021-07-03.at.10.08.33.am.mp4

This plugin is awesome as it implements one of my preferred Typora's functionalities : automatic handling of URL pasting.
I love being able to copy a URL, select some text (or not if I just want one word) then ctrl+K to automagically make a perfect Markdown link.

However, I really don't want to use ctrl+v for that, and this plugin even though I set a hotkey to ctrl+k continues to override ctrl+v and it shows each time I paste something that is detected wrongfully or not as an URL : as an example, pasting <% tp.file.cursor() %> anywhere gives [](<%3C% tp.file.cursor() %%3E>) and using shift+ctrl+v doesn't bypass this, so I have to either manually delete all the junk added by the plugin or stop using the plugin :'(

Please, just use the hotkey setting to activate the plugin !

Hi, i just created a GitHub account, just to tell you that your plugin is great.
However, I ran exactly in the same issues described earlier. Here is my paste result.

<<title: %3C%+ tp.file.title %%3E>>

I tried to change the hotkey, i tried to change almost every possible setting.
Copy/Paste would only work, if i turn your plugin off. Which I need to do for now.
I really hope you can solve this mystery, because, as mentioned, it was really useful for me.

Thank for your work on that.
Sincerely, N

This is happening for me even when I'm not using Templater.

I'm using Ctrl+K as my "paste into link" hotkey, and Ctrl+V'ing into a selection still pastes the link "inside" it.

I will see what I can do about this, most likely over the weekend.

I too am wishing this plug-in would fallback to standard paste behavior in more scenarios. Regarding @NeighNeighNeigh's example, perhaps just testing the selected text for isUrl would solve the use case of replacing an existing link?

Allowing the option of an alternate link pasting hotkey would be nice, though.

Also thanks for this work!

Yes, I ran into the same situation a few times while going through old notes and editing them.
Trying to paste a word over an URL instead leads to the word becoming hyperlinked with said URL. It would be better if it was just replaced with ctrl + k so there isn't an overlap with functions of traditional copy-and-pasting.

vii33 commented

Same issue here. I love the plugin but it is quite error prone when copying text around.
As an idea perhaps you could just add a keyboard shortcut (which could by default be CTRL+V), so people can change it to their likings? Then everybody woulde be happy, I guess.

Is this plugin maintained at all @denolehov? Could the people with the pull requests take over or just also maintain?

BumbrT commented

Looks like, I created duplicate issue here #53.
You can use my fork https://github.com/BumbrT/obsidian-url-into-selection through BRAT plugin. Only one line difference with this repo: disabled editor paste handling.

If anyone's curious, I also made my own version of this plugin that implements this as an option (and also allows bypassing the plugin by holding Shift otherwise): https://github.com/jose-elias-alvarez/obsidian-paste-link