Tip of the day: Adding links to Textarea on OS X
The first snippet here checks to see if current cursor position has a link set:
dim n as NSTextViewMBS = textarea1.NSTextViewMBS
dim a as NSAttributedStringMBS = n.textStorage
if a.Length > 0 then
dim d as Dictionary = n.selectedTextAttributes
dim r as NSRangeMBS = n.selectedRange
if r.Location < a.Length then
dim l as string = a.attributeAtIndex(a.NSLinkAttributeName, r.Location)
InputField.Text = l
Return
end if
end if
InputField.Text = ""
Second snippet shows how to remove/add a link to the current selection:
dim n as NSTextViewMBS = TextArea1.NSTextViewMBS
dim a as NSMutableAttributedStringMBS = n.textStorage
if InputField.Text = "" then
// remove link
a.removeAttribute(a.NSLinkAttributeName, n.selectedRange)
else
// add one
a.addAttribute(a.NSLinkAttributeName, InputField.text, n.selectedRange)
end if
