This is an html source code editor, there is no guarantee that the selected text does not contain other tags. You cannot just assume it is text a plunk it in the middle of an <a> tag.
There are three possible behaviors for the insert link action when text is selected:
1) Delete the selected text and insert the <a> tag (this is what currently happens)
2) Ignore the selected text and insert the <a> tag either before or after it depending on the current cursor position at the start or end of the selection.
3) Wrap the selected text in <a> tags.
1) and 2) have the advantage that the insertion of the <a> tag can be guaranteed to not produce invalid HTML. Trying to make that guarantee with (3) is very difficult. The best that you could probably do is detect a potential problem and bail with an error message.
|