@@ -19,21 +19,22 @@ class X::CannotStringify is Exception {
1919 }
2020}
2121
22-
2322# | Convenience helper to throw X::CannotStringify easily
2423sub throw-cannot-stringify ($ type , $ conversion-method , $ conversion-result ) is export {
2524 X::CannotStringify . new (: $ type , : $ conversion-method , : $ conversion-result ). throw
2625}
2726
2827
29- # | A directly renderable styled text span
30- class RenderSpan is export {
31- # XXXX: Include an ID or reference marker of some type to handle user
32- # interaction with the rendered span?
28+ # Forward declaration
29+ class StringSpan { ... }
3330
34- has Str : D $ . color = ' ' ;
35- has Str : D $ . text = ' ' ;
36- has UInt $ ! width ;
31+ # | A directly renderable styled text span, optionally remembering the
32+ # | StringSpan it was rendered from (providing a path to StringSpan.attributes)
33+ class RenderSpan is export {
34+ has StringSpan $ . string-span ;
35+ has Str : D $ . color = ' ' ;
36+ has Str : D $ . text = ' ' ;
37+ has UInt $ ! width ;
3738
3839 # | Lazily calculate and cache duospace width
3940 method width (--> UInt : D ) {
@@ -73,7 +74,8 @@ class StringSpan does SemanticSpan {
7374 # | Render the string into a RenderSpan according to its attributes
7475 method render (--> RenderSpan: D ) {
7576 # XXXX: Hack: Just transfer over the color attribute
76- RenderSpan. new (text => $ . string , color => % . attributes <color > // ' ' )
77+ RenderSpan. new (string-span => self , text => $ . string ,
78+ color => % . attributes <color > // ' ' )
7779 }
7880
7981 # | Apply current span attributes on top of parent attributes, returning a
@@ -179,8 +181,8 @@ class MarkupString does SemanticText is export {
179181# Helper functions to build spans/trees
180182
181183# | Helper function to build a RenderSpan, ready for Widget.render-line-spans
182- sub render-span (Str : D $ text = ' ' , Str : D $ color = ' ' ) is export {
183- RenderSpan. new (: $ text , : $ color )
184+ sub render-span (Str : D $ text = ' ' , Str : D $ color = ' ' , StringSpan : $ string-span ) is export {
185+ RenderSpan. new (: $ text , : $ color , : $ string-span )
184186}
185187
186188# | Helper function to build a StringSpan (a SemanticSpan with NO interpolants)
0 commit comments