make-preedit-underlines ( gadget text range -- underlines )


Vocabulary
ui.backend.cocoa.views.private

Inputs
gadgetan object
textan object
rangean object


Outputs
underlinesan object


Definition


:: make-preedit-underlines
( gadget text range -- underlines )
f gadget preedit-selection-mode?<<
{ } clone :> underlines! text
{ ulong { id SEL } } "length" send
:> text-length 0 0 <NSRange> :> effective-range text
{ id { id SEL } } "string" send
CF>string :> str str utf16n encode
:> byte-16n 0 :> cp-loc! "NSMarkedClauseSegment" <NSString>
:> segment-attr [
effective-range [ location>> ] [ length>> ] bi +
text-length <
] [
text segment-attr effective-range
[ location>> ] [ length>> ] bi + effective-range >c-ptr
{ id { id SEL id ulong void* } }
"attribute:atIndex:effectiveRange:" send drop
1 :> thickness! range location>> effective-range
location>> =
[ 2 thickness! t gadget preedit-selection-mode?<< ] when
underlines effective-range
[ location>> ] [ length>> ] bi over +
[ str swap >codepoint-index ] bi@ swap -
:> len cp-loc cp-loc len + dup cp-loc! 2array
thickness 2array suffix underlines!
] while underlines length 1 =
[ underlines first first 2 2array 1array ] [ underlines ] if
;