Maybe do like Xojo and complete the word with dimmer text.
A TextArea is a NSScrollView. Get its documentView for the NSTextView and from that get textStorage. NSTextStorage is a subclass of NSMutableAttributedString which has the methods for adding attributes, like background color.
This code goes in a Module, only tested for 32bit, no error checking. Should be easy to update for 64bit. I used Xcode to get the attribute constant name.
[code]Sub setTextBGColor(extends ta As TextArea, start As integer, length As integer, bgColor As Color)
declare function NSClassFromString lib “Cocoa” (aClassName as CFStringRef) as Ptr
declare function docView lib “Cocoa” selector “documentView” (id As Ptr) as Ptr
declare function textStore lib “Cocoa” selector “textStorage” (id As Ptr) as Ptr
declare function colRGBA lib “Cocoa” selector “colorWithCalibratedRed:green:blue:alpha:” _
(cls As Ptr, r As single, g As single, b As single, a As single) as Ptr
declare sub addAttrib lib “Cocoa” selector “addAttribute:value:range:” _
(id As Ptr, name As CFStringRef, value As Ptr, aRange As NSRange32)
declare sub release lib “Cocoa” selector “release” (id As Ptr)
dim ts As Ptr = textStore(docView(Ptr(ta.Handle)))
dim range As NSRange32
range.location = start
range.length = length
dim colorCls As Ptr = NSClassFromString(“NSColor”)
dim col As Ptr = colRGBA(colorCls, _
bgColor.Red/255, bgColor.Green/255, bgColor.Blue/255, 1-bgColor.Alpha/255)
addAttrib(ts, “NSBackgroundColor”, col, range)
release(col)
End Sub
Structure NSRange32
location As UInt32
length As UInt32[/code]
demo…
TextArea1.Text = "abcdefg"
TextArea1.setTextBGColor(2, 2, &c00FF00) //highlights "cd" in green
references…
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSScrollView_Class/
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextStorage_Class/
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableAttributedString_Class/
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/index.html#//apple_ref/doc/constant_group/Character_Attributes