Adding an "Add Link" contextual menu to TextArea

This is for macOS.

You can paste live hypertext links (created with other apps) into a TextArea and they will be live (blue and underlined – these are not just the URL, but contain the text to display to the user and an embedded active URL). Right-clicking on such links brings up a number of useful options (Edit Link, Remove Link, etc.).

I’ve used MBS to add the ability to create such links from the selected text with a right-click. However, to add this option (Add Link) in the ConstructContextualMenu event I lose the host of right-click options that normally appear.

My question is, how to have a right click show a new option (Add Link) and still include all of the other options provided by TextArea in macOS? I’ve looked for a NSTextViewMBS flag that would allow that and have come up with nothing.

You use NSMutableAttributedStringMBS class.

Call addAttribute and pass NSLinkAttributeName as attribute name and your range to use (zero based).

You may do that on TextArea1.NSTextViewMBS.textStorage directly.

Thanks, but I’m already doing that and it works perfectly. That’s not my question. My question is: is it possible to have a TextArea show the option to “Add Link” (supplied by macOS) in the right click menu when there is selected text? Since the TextArea already knows how to add Link-related menu items when clicking on live links, I wonder how to have it include the menu option to add such a link (which I will handle and use MBS to create them).

If you look at Mail, you’ll see a right click on selected text shows all of the usual contextual menu options PLUS menu items for Link.

I recall this depends on wether you return true or false to the constructcontextualmenu event, to have the other menus displayed or not.

That’s what I assumed, too, but it doesn’t make any difference in my tests. If I add a menuItem in ConstructContextualMenu it is the only item in the contextual menu (except for a Services menu) whether I return true or false.