steveathon / bootstrap-wysiwyg

Tiny bootstrap-compatible WYSIWYG rich text editor
MIT License
661 stars 1.71k forks source link

Cannot Create Hyperlink Without Text Selected #127

Open spreadred opened 6 years ago

spreadred commented 6 years ago

It seems as though only Chrome is capable of adding a hyperlink directly from the hyperlink button, without having previously typed the text for the link and then selected it prior to clicking the hyperlink button.

Steps to reproduce:

  1. Without typing or selecting anything in the editor, click the hyperlink button
  2. Type the destination address
  3. Click "Add"
  4. Nothing is added to the editor in IE 11, Edge and Firefox - Chrome adds the hyperlink with the text the same as the destination address.

I'm not sure what the desired behavior is, but I think Chrome's behavior is likely the desired behavior by the end user.

spreadred commented 6 years ago

From the mozilla docs on executecommand:

createLink Creates an anchor link from the selection, only if there is a selection. This requires the HREF URI string to be passed in as a value argument. The URI must contain at least a single character, which may be a white space. (Internet Explorer will create a link with a null URI value.)

It appears as though the solution to this is going to be creating a fake one character selection at the cursor position if nothing is selected.

hungqcao commented 6 years ago

@kaptainkommie I fixed this issue with my latest commit #126 Basically we will create a fake text element and move selection to that element when there is no current selection. Thanks for taking a look at it.