obsidian-url-into-selection icon indicating copy to clipboard operation
obsidian-url-into-selection copied to clipboard

Don't override standard ctrl+v functionality

Open Mpic opened this issue 3 years ago • 18 comments

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 !

Mpic avatar May 14 '21 16:05 Mpic

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.

denolehov avatar May 15 '21 11:05 denolehov

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.

Mpic avatar May 16 '21 20:05 Mpic

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.

NeighNeighNeigh avatar May 17 '21 07:05 NeighNeighNeigh

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).

Mpic avatar May 17 '21 07:05 Mpic

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

NeighNeighNeigh avatar May 17 '21 07:05 NeighNeighNeigh

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.

Mpic avatar May 20 '21 07:05 Mpic

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.

HaujetZhao avatar Jun 18 '21 07:06 HaujetZhao

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.

Cito avatar Jun 18 '21 08:06 Cito

Thought maybe a video demonstrating the issue might be helpful?

https://user-images.githubusercontent.com/4795315/124337770-9cd40100-dbe7-11eb-8f8c-e8e4ebf2c019.mp4

NeighNeighNeigh avatar Jul 03 '21 00:07 NeighNeighNeigh

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

mementori avatar Aug 31 '21 18:08 mementori

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.

firinael avatar Sep 09 '21 20:09 firinael

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

denolehov avatar Sep 09 '21 20:09 denolehov

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!

mitchallain avatar Nov 21 '21 17:11 mitchallain

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.

ghost avatar Feb 03 '22 21:02 ghost

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.

vii33 avatar Mar 06 '22 00:03 vii33

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

NomarCub avatar Sep 08 '22 13:09 NomarCub

Looks like, I created duplicate issue here https://github.com/denolehov/obsidian-url-into-selection/issues/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.

BumbrT avatar Oct 23 '23 07:10 BumbrT

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

jose-elias-alvarez avatar Jan 07 '24 13:01 jose-elias-alvarez