1313using Windows . UI . Xaml . Media ;
1414using Windows . UI . Xaml . Media . Imaging ;
1515
16- // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
17-
1816namespace Quarrel . Controls . Message
1917{
2018 public sealed partial class MessageRenderer : UserControl
2119 {
20+ private const bool IsTextSelectable = false ;
21+ private const bool IsCodeSelectable = true ;
22+
2223 public static readonly DependencyProperty TextProperty = DependencyProperty . Register (
23- " Text" ,
24+ nameof ( Text ) ,
2425 typeof ( string ) ,
2526 typeof ( MessageRenderer ) ,
2627 new PropertyMetadata ( null , OnTextChanged )
@@ -30,7 +31,6 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE
3031 {
3132 var messageRenderer = ( MessageRenderer ) d ;
3233 messageRenderer . textBlock . Blocks . Clear ( ) ;
33- var parser = new Parser ( ) ;
3434 var tree = Parser . ParseAST ( ( string ) e . NewValue , true , false ) ;
3535 var modTree = AdjustTree ( tree ) ;
3636 Parse ( modTree , messageRenderer . textBlock . Blocks ) ;
@@ -83,6 +83,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
8383 FontSize = container . FontSize ,
8484 FontStretch = container . FontStretch ,
8585 TextDecorations = container . TextDecorations ,
86+ IsTextSelectionEnabled = IsCodeSelectable ,
8687 Blocks = { codeParagraph }
8788 }
8889 } ;
@@ -106,7 +107,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
106107 FontSize = container . FontSize ,
107108 FontStretch = container . FontStretch ,
108109 TextDecorations = container . TextDecorations ,
109- IsTextSelectionEnabled = true ,
110+ IsTextSelectionEnabled = IsCodeSelectable ,
110111 Text = codeBlock . Content
111112 }
112113 } ;
@@ -225,11 +226,11 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
225226 }
226227 }
227228 break ;
228- case S u :
229+ case S s :
229230 {
230231 var inline = new Span ( ) { TextDecorations = TextDecorations . Strikethrough } ;
231232 inlineCollection . Add ( inline ) ;
232- foreach ( AST child in u . Children . Reverse ( ) )
233+ foreach ( AST child in s . Children . Reverse ( ) )
233234 {
234235 stack . Push ( ( child , inline . Inlines ) ) ;
235236 }
@@ -250,15 +251,14 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
250251 FontSize = container . FontSize ,
251252 FontStretch = container . FontStretch ,
252253 TextDecorations = container . TextDecorations ,
253- IsTextSelectionEnabled = true ,
254+ IsTextSelectionEnabled = IsCodeSelectable ,
254255 Text = inlineCode . Content
255256 }
256257 } ;
257258 }
258259 break ;
259260 case Timestamp timeStamp :
260261 {
261-
262262 InlineUIContainer container = new InlineUIContainer ( ) ;
263263 inlineCollection . Add ( container ) ;
264264 container . Child = new Border ( )
@@ -271,7 +271,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
271271 FontSize = container . FontSize ,
272272 FontStretch = container . FontStretch ,
273273 TextDecorations = container . TextDecorations ,
274- IsTextSelectionEnabled = true ,
274+ IsTextSelectionEnabled = IsTextSelectable ,
275275 Text = timeStamp . Format switch
276276 {
277277 "F" or "" => timeStamp . Time . ToString ( "F" ) ,
@@ -300,7 +300,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
300300 FontSize = container . FontSize ,
301301 FontStretch = container . FontStretch ,
302302 TextDecorations = container . TextDecorations ,
303- IsTextSelectionEnabled = true ,
303+ IsTextSelectionEnabled = IsTextSelectable ,
304304 Text = roleMention . RoleID
305305 }
306306 } ;
@@ -320,7 +320,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
320320 FontSize = container . FontSize ,
321321 FontStretch = container . FontStretch ,
322322 TextDecorations = container . TextDecorations ,
323- IsTextSelectionEnabled = true ,
323+ IsTextSelectionEnabled = IsTextSelectable ,
324324 Text = mention . UserID
325325 }
326326 } ;
@@ -340,7 +340,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
340340 FontSize = container . FontSize ,
341341 FontStretch = container . FontStretch ,
342342 TextDecorations = container . TextDecorations ,
343- IsTextSelectionEnabled = true ,
343+ IsTextSelectionEnabled = IsTextSelectable ,
344344 Text = channel . ChannelID
345345 }
346346 } ;
@@ -362,7 +362,8 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
362362 FontSize = container . FontSize ,
363363 FontStretch = container . FontStretch ,
364364 TextDecorations = container . TextDecorations ,
365- Blocks = { codeParagraph }
365+ IsTextSelectionEnabled = IsTextSelectable ,
366+ Blocks = { codeParagraph } ,
366367 }
367368 } ;
368369 foreach ( AST child in spoiler . Children . Reverse ( ) )
0 commit comments