link icon indicating copy to clipboard operation
link copied to clipboard

Feat: auto-create the link block when a non-image link is pasted

Open antoineol opened this issue 2 years ago • 2 comments

Here is a feature I need for my project, and I thought it would be good to suggest a merge in the main repo.

Use case: when users paste links in the editor, in an empty paragraph, it should automatically attempt to create a link block.

It may introduce a couple of UX issues, so I also changed:

  • if the auto-link fails, it falls back to replacing the failed link with a paragraph with the raw link (only for auto-links, not for user-created link blocks)
  • a tune has been added: replace the embed with a raw link, in case the user's attempt was not to create a link block.
  • Those behaviors are only enabled if the auto-link is enabled.

Improvements I've identified, but I don't know how to do them:

  • [ ] I added 2 configs. In the second one, the user should repeat the plugin key, just because I wasn't able to get it dynamically in the plugin code (any idea about how to do that?)
  • [x] When the URL is pasted and the block created, auto-show the tune menu

If you have any suggestions for them, I would be happy to improve the code.

antoineol avatar Jun 25 '23 14:06 antoineol

Вся ваша проблема решается , следующим куском кода `static get pasteConfig() { return { // ... tags // ... files patterns: { link: /https?://(www.)?[-a-zA-Z0-9@:%.+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%+.~#?&//=]*)/i } } }

onPaste(event){
    switch (event.type){
        // ... case 'tag'
        // ... case 'file'
        case 'pattern':
            const link = event.detail.data;

            this.data.link=link;
            this.nodes.input.textContent=link;


            var event = new KeyboardEvent('keypress', {keyCode: 13});
            this.startFetching(event);



            break;
    }
}`

noistudio avatar Jul 12 '23 07:07 noistudio

Will this ever be merged or should I also fork the project and make my own version of it?

Slowl avatar Apr 22 '24 22:04 Slowl