-
Notifications
You must be signed in to change notification settings - Fork 551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clicking on link icon when selected text is already a link does not show the current URL #185
Comments
Not so easy to make this kind of things, but you can get the selection value before calling callback of pell. Here is a working example: 1/ Add a dedicated function to get only links and the href value: function getSelectedParagraphText() {
let selection;
if (window.getSelection) {
selection = window.getSelection();
} else if (document.selection) {
selection = document.selection.createRange();
}
let parent = selection.anchorNode;
while (parent != null && parent.localName !== "a") {
parent = parent.parentNode;
}
if (parent == null) {
return "";
} else {
return parent.getAttribute('href');
}
} 2/ Then in pell, simply call the function on link handler: {
name: 'link',
title: 'Add URL link',
icon: '<i class="fa fa-fw fa-link fa-sm"></i>',
result: () => {
let link = getSelectedParagraphText() || '';
const url = window.prompt('Enter the link URL', link);
if (url) window.pell.exec('createLink', url)
}
} @jaredreich if you're interested, I think this feature can be a great idea for a new version ? |
OK thanks @algorys for your tips, in the meantime I was trying to do it, here is my first implementation: (inspired from anuradhaspidy/widgeditor#21)
|
It depends on what you want to do next, I stayed on something very simple because the goal of this editor is to be as light as possible. |
Hi,
Once a selected text has been converted into a link using the link icon, there is no way to know what the link URL was and modify it.
When I select text that is already a link and I click on the link icon, the prompt that asks what link to use has a blank content. I would expect it to be pre-filled with the current link content.
Would it be possible and not too difficult to implement this?
Thanks in advance
The text was updated successfully, but these errors were encountered: