react-quill icon indicating copy to clipboard operation
react-quill copied to clipboard

Link popup on edit

Open paigeflourin opened this issue 5 years ago • 3 comments

i tried this and it works https://github.com/zenoamaro/react-quill/issues/203 and here https://github.com/zenoamaro/react-quill/issues/131 . but how do i get the same behavior when editing a link?

image

to this:

image

paigeflourin avatar Mar 14 '19 05:03 paigeflourin

@paigeflourin Seems I've found some solution, I hope it will helpful for you You can look how it realized in source, for example check a theme file ./node_modules/quill/themes/snow.js Then implement something like this with your logic

handlers: {
    link (value) {
        if (value) {
            let range = this.quill.getSelection()
            if (range == null || range.length === 0) {
                return
            }

            let tooltip = this.quill.theme.tooltip
            tooltip.edit('link', '')
        } else {
            this.quill.format('link', false)
        }
    },
// ...
}

I needed also allow enter only valid links, so I changed base behavior of link creation (maybe more better solution exists)

const LinkInstance = Quill.import('formats/link')
const baseLinkCreate = LinkInstance.create

LinkInstance.create = function (value) {
    if (value) {
        if (!/^https?:\/\/(\S+)\.(\S+)$/.test(value)) {
            return document.createElement('a')
        }
    }

    return baseLinkCreate.call(this, value)
}

MaxRazen avatar Jan 29 '20 21:01 MaxRazen

did you already got the solution?

i wonder about this as well

Hndry avatar Jun 18 '20 11:06 Hndry

@MaxRazen this solution wroks for create link , but user can edit that link without any validation.

you should change "edit" function in "base.js" file too handle that

Hoomanmsh avatar Dec 02 '21 07:12 Hoomanmsh