]> gitweb.factorcode.org Git - factor.git/commitdiff
Improved background rendering when selecting text, including emojis
authorKUSUMOTO Norio <norio@mac-mini.local>
Sat, 27 Jul 2019 00:56:37 +0000 (09:56 +0900)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 30 Jul 2019 07:12:41 +0000 (02:12 -0500)
basis/core-text/core-text.factor

index 98b6c4a189eaf2ac2e7f38ba2fa07ec127b0bd14..ee3e7a1f8e15a58307cf8eea1f5508b0f9a0df58 100644 (file)
@@ -5,7 +5,8 @@ assocs cache colors combinators core-foundation
 core-foundation.attributed-strings core-foundation.strings
 core-graphics core-graphics.types core-text.fonts destructors
 fonts init kernel locals make math math.functions math.order
-math.vectors memoize namespaces sequences strings ;
+math.vectors memoize namespaces sequences strings
+io.encodings.utf16n io.encodings.string ;
 IN: core-text
 
 TYPEDEF: void* CTLineRef
@@ -62,7 +63,7 @@ render-loc render-dim ;
     {
         [ >>width ]
         [ >>ascent ]
-        [ >>descent ]
+        [ dup 0 < [ -1 * ] when >>descent ]
         [ >>leading ]
     } spread ; inline
 
@@ -88,7 +89,9 @@ render-loc render-dim ;
     bi-curry* bi ;
 
 : selection-rect ( dim line selection -- rect )
-    [ start>> ] [ end>> ] bi
+    [let [ start>> ] [ end>> ] [ string>> ] tri :> ( start end string )
+     start end [ 0 swap string subseq utf16n encode length 2 / >integer ] bi@
+    ]
     [ f CTLineGetOffsetForStringIndex round ] bi-curry@ bi
     [ drop nip 0 ] [ swap - swap second ] 3bi <CGRect> ;